Swift实现全屏侧滑

2016-05-24  本文已影响574人  不简单的风度

之前看到别人用OC实现了全屏侧滑,感觉挺实用的,今天用swift实现了一下
具体如下:
1.在AppDelegate中添加导航控制器

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用来跳转到第二个界面,这一步就不放代码了

3.在第二个界面禁用系统手势,添加自己的手势

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
    }

至此就完成了全屏侧滑。自己写的界面太丑,就不上效果图了。

上一篇下一篇

猜你喜欢

热点阅读