我想禁用UITabBarViewController
在特定UITabBarItem
切换到长按tag
的功能。
我尝试的是
UITabBarViewController
UIGestureRecognizerDelegate
归为UILongPressGestureRecognizer
delegate
并将其self
设置为gestureRecognizerShouldBegin
NO
并将其返回UITapGestureRecognizer *recognizer
但它没有用。
请注意,我已将UITabBarItem
添加到[self.tabBar.subviews[2] addGestureRecognizer:recognizer]
之一,如下所示:
UITapGestureRecognizer
它工作正常。即使长时间按下,我也希望立即禁用识别长按并立即触发dataset
。
由于
答案 0 :(得分:1)
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 0.5;
[self addGestureRecognizer:longPress];
和句柄长按法
- (void)handleLongPress:(UILongPressGestureRecognizer*)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"UIGestureRecognizerStateEnded");
//Do Whatever You want on End of Gesture
[[[[self.tabBarController tabBar]items]objectAtIndex:0]setEnabled:FALSE];
}
else if (sender.state == UIGestureRecognizerStateBegan){
NSLog(@"UIGestureRecognizerStateBegan.");
//Do Whatever You want on Began of Gesture
}
}
在AppDelegate
来电
UITabBarControllerDelegate
成为didFinishLaunchingWithOptions:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
tabBarController.delegate = (id)self;
并添加此方法:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;
{
if (viewController.restorationIdentifier isEqualToString:@"foo")
return YES;
else
return NO;
}