之前看到別人用OC實(shí)現(xiàn)了全屏側(cè)滑,感覺挺實(shí)用的齿税,今天用swift實(shí)現(xiàn)了一下
具體如下:
1.在AppDelegate中添加導(dǎo)航控制器
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let vc = ViewController()
let nav = UINavigationController.init(rootViewController: vc)
window?.rootViewController = nav
return true
}
2.在第一個界面上放一個button用來跳轉(zhuǎn)到第二個界面段直,這一步就不放代碼了
3.在第二個界面禁用系統(tǒng)手勢吃溅,添加自己的手勢
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.view.backgroundColor = UIColor.cyanColor()
configViews()
}
func configViews() {
let target = self.navigationController?.interactivePopGestureRecognizer?.delegate
let pan = UIPanGestureRecognizer.init(target: target, action: Selector("handleNavigationTransition:"))
pan.delegate = self
self.view.addGestureRecognizer(pan)
self.navigationController?.interactivePopGestureRecognizer?.enabled = false
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
if self.childViewControllers.count == 1 {
return false
}
return true
}
至此就完成了全屏側(cè)滑。自己寫的界面太丑鸯檬,就不上效果圖了决侈。