![](/img/trans.png)
[英]How to disable UILongPressGestureRecognizer on UICollectionViewCell after there is a long press?
[英]Disable switching tabs after long press on UITabBarItem
我想禁用UITabBarViewController
的切換到長按能力UITabBarItem
在特定的tag
。
我試過的是
UITabBarViewController
子類化為UIGestureRecognizerDelegate
UILongPressGestureRecognizer
並將其delegate
設置為self
gestureRecognizerShouldBegin
,使其返回NO
但這沒有用。
請注意,我已經將UITapGestureRecognizer *recognizer
添加到UITabBarItem
之一,如下所示:
[self.tabBar.subviews[2] addGestureRecognizer:recognizer]
而且效果很好。 我只想禁用識別長按並立即觸發UITapGestureRecognizer
,即使長按也是如此。
謝謝
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
}
}
在didFinishLaunchingWithOptions:
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.