hidesBarsOnSwipe禁用Left&右手滑动手势

时间:2015-12-29 12:07:31

标签: ios swift uinavigationcontroller swift2

在下面的代码中,当我添加hidesBarsOnSwipe属性时,我的滑动左右功能以某种方式被禁用并开始不起作用。如何让它们同时工作?

 let leftSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
 let rightSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))

  leftSwipe.direction = .Left
  rightSwipe.direction = .Right

  view.addGestureRecognizer(leftSwipe)
  view.addGestureRecognizer(rightSwipe)

  self.navigationController?.hidesBarsOnSwipe = true

1 个答案:

答案 0 :(得分:0)

   override func viewDidLoad() {
        super.viewDidLoad()

        var leftSwipe= UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
        swipeRight.direction = UISwipeGestureRecognizerDirection.Left
        self.view.addGestureRecognizer(leftSwipe)

        var rightSwipe= UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
        swipeDown.direction = UISwipeGestureRecognizerDirection.Right
        self.view.addGestureRecognizer(rightSwipe)

        self.navigationController?.hidesBarsOnSwipe = false
        self.navigationController?.setNavigationBarHidden(false, animated:   true)
 }

    func handleSwipes(gesture: UIGestureRecognizer) {

        if let swipeGesture = gesture as? UISwipeGestureRecognizer {
            switch swipeGesture.direction {
                case UISwipeGestureRecognizerDirection.Right:
                    print("Swiped right")
                case UISwipeGestureRecognizerDirection.Left:
                    print("Swiped left")
                default:
                    break
            }
        }