我想禁用整個視圖的用戶交互,但也允許在視圖上點按手勢。假設主視圖上方有一個菜單,並且如果用戶再次點擊主視圖,則後菜單消失。但是,只要顯示菜單,則應禁用與主視圖的所有其他交互。 這裏是我嘗試做的是: 我定義的tapGestureRecognizer這樣的:禁用用戶交互但在UIViewController中允許點按手勢
@interface GroupMasterViewController() <SWRevealViewControllerDelegate>
@property NSMutableArray *groups;
@property (nonatomic, strong) UITapGestureRecognizer *tapGestureRecognizer;
@end
在我viewDidLoad方法我有這樣的:
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self.revealViewController action:@selector(rightRevealToggle:)];
[self.view addGestureRecognizer:self.tapGestureRecognizer];
self.tapGestureRecognizer.enabled = NO;
而且在委託方法,被解僱時,菜單打開或關閉:
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position
{
if (position == FrontViewPositionLeftSide) {
self.tapGestureRecognizer.enabled = YES;
self.view.userInteractionEnabled = NO;
self.tabBarController.tabBar.userInteractionEnabled = NO;
}
else if (position == FrontViewPositionLeft){
self.tapGestureRecognizer.enabled = NO;
self.view.userInteractionEnabled = YES;
self.tabBarController.tabBar.userInteractionEnabled = YES;
}
}
問題是,tapGestureRecognizer不再工作了,如果我禁用用戶交互。
非常感謝您的幫助。
要禁用整個視圖,以便UITapGestureRecognizer不會work.Please使意見的主視圖的子視圖,並啓用和禁用你想 – Rose