SWRevealViewController close rear view when tapping front view

前端 未结 9 1593
夕颜
夕颜 2020-12-09 04:18

I am using SWRevealViewController in order to implement a side nav menu in my app. I would like to make it so that the front view cannot be interacted with when

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 05:07

    EDIT: Change UIView's autoresizingMask to suit Swift 2, thanks to Marroc's comment

    This is Swift-SWRevealViewController 2.x version of @avdyushin's answer:

    func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition) {
        let tagId = 4207868622
    
        if revealController.frontViewPosition == FrontViewPosition.Right {
            let lock = self.view.viewWithTag(tagId)
            UIView.animateWithDuration(0.25, animations: {
                    lock?.alpha = 0
                }, completion: {(finished: Bool) in
                    lock?.removeFromSuperview()
                }
            )
            lock?.removeFromSuperview()
        } else if revealController.frontViewPosition == FrontViewPosition.Left {
            let lock = UIView(frame: self.view.bounds)
            lock.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
            lock.tag = tagId
            lock.alpha = 0
            lock.backgroundColor = UIColor.blackColor()
            lock.addGestureRecognizer(UITapGestureRecognizer(target: self.revealViewController(), action: "revealToggle:"))
            self.view.addSubview(lock)
            UIView.animateWithDuration(0.75, animations: {
                    lock.alpha = 0.333
                }
            )
        }
    }
    

提交回复
热议问题