iOS 11 问题 - 如果手势添加到导航栏,栏按钮操作不会触发
iOS 11 issue - bar button action does not fire if gesture added to navigation bar
这在 iOS 10 上运行良好。但在 iOS 11 上不起作用。showFlyoutMenu
未启动。
gestureLeftArrow = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(leftArrowGesture:)];
[self.navigationController.navigationBar addGestureRecognizer:gestureLeftArrow];
gestureRightArrow = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rightArrowGesture:)];
[self.navigationController.navigationBar addGestureRecognizer:gestureRightArrow];
UIImage *image = [[UIImage imageNamed:@"hamburger-new.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *flyoutButton = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(showFlyoutMenu)];
self.navigationItem.rightBarButtonItem = flyoutButton;
您应该将 cancelsTouchesInView
个手势识别器设置为 false
。
参见:cancelsTouchesInView
Discussion
When this property is true (the default) and the receiver recognizes its gesture, the touches of that gesture that are pending are not delivered to the view and previously delivered touches are cancelled through a touchesCancelled(_:with:) message sent to the view. If a gesture recognizer doesn’t recognize its gesture or if the value of this property is false, the view receives all touches in the multi-touch sequence.
这在 iOS 10 上运行良好。但在 iOS 11 上不起作用。showFlyoutMenu
未启动。
gestureLeftArrow = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(leftArrowGesture:)];
[self.navigationController.navigationBar addGestureRecognizer:gestureLeftArrow];
gestureRightArrow = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rightArrowGesture:)];
[self.navigationController.navigationBar addGestureRecognizer:gestureRightArrow];
UIImage *image = [[UIImage imageNamed:@"hamburger-new.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *flyoutButton = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(showFlyoutMenu)];
self.navigationItem.rightBarButtonItem = flyoutButton;
您应该将 cancelsTouchesInView
个手势识别器设置为 false
。
参见:cancelsTouchesInView
Discussion
When this property is true (the default) and the receiver recognizes its gesture, the touches of that gesture that are pending are not delivered to the view and previously delivered touches are cancelled through a touchesCancelled(_:with:) message sent to the view. If a gesture recognizer doesn’t recognize its gesture or if the value of this property is false, the view receives all touches in the multi-touch sequence.