mesala view'lar arası geçiş için şöyle birşeyler yapılabilir.
verdiğim kodu boş bir proje açıp, viewController'a kopyalayın.
import UIKit
class ViewController: UIViewController {
var anotherView:UIView! = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var showButton:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
showButton.frame = CGRectMake((self.view.frame.size.width - (self.view.frame.size.width * 0.3)) / 2, (self.view.frame.size.height - (self.view.frame.size.height * 0.08)) / 2, self.view.frame.size.width * 0.3, self.view.frame.size.height * 0.08)
showButton.backgroundColor = UIColor.redColor()
showButton.addTarget(self, action: "showAnotherView", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(showButton)
}
func showAnotherView() {
if self.anotherView == nil {
self.anotherView = UIView(frame: CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height))
self.anotherView.backgroundColor = UIColor.redColor()
self.view.addSubview(self.anotherView)
var dismissButton:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
dismissButton.frame = CGRectMake((self.view.frame.size.width - (self.view.frame.size.width * 0.3)) / 2, (self.view.frame.size.height - (self.view.frame.size.height * 0.08)) / 2, self.view.frame.size.width * 0.3, self.view.frame.size.height * 0.08)
dismissButton.backgroundColor = UIColor.whiteColor()
dismissButton.addTarget(self, action: "dismissAnotherView", forControlEvents: UIControlEvents.TouchUpInside)
self.anotherView.addSubview(dismissButton)
UIView.animateWithDuration(0.4, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
self.anotherView.frame = self.view.frame
}, completion: { (Bool) -> Void in
})
}
}
func dismissAnotherView() {
if self.anotherView != nil {
UIView.animateWithDuration(0.4, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
self.anotherView.frame = CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)
}, completion: { (Bool) -> Void in
self.anotherView.removeFromSuperview()
self.anotherView = nil
})
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}