在我的viewDidLoad中设置
UISwipeGestureRecognizer *swipeRecognizerU = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUpDetected:)]; swipeRecognizerU.direction = UISwipeGestureRecognizerDirectionUp; [self.view addGestureRecognizer:swipeRecognizerU];
当我通过弹出窗口加载新视图时,我需要禁用该手势
// show popup view
-(IBAction)showPopup:(id)sender
{
MJDetailViewController *detailViewController = [[MJDetailViewController alloc] initWithNibName:@"MJDetailViewController" bundle:nil];
[self presentPopupViewController:detailViewController animationType:MJPopupViewAnimationSlideBottomBottom];
}
在取消弹出视图后,我需要设置滑动手势。
// hide popup view
-(IBAction)hidePopup:(id)sender
{
[self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationSlideBottomBottom];
}
如何做到这一点?
答案 0 :(得分:6)
我认为UIGestureRecognizer
已启用名为的属性。你试试这个,应该可以禁用你的滑动:
swipeGestureRecognizer.enabled = NO;
答案 1 :(得分:1)
你需要在这里设置委托。
前:
swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeleft:)];
swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
swipeleft.delegate = self;
[self.view addGestureRecognizer:swipeleft];
然后添加功能
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ((touch.view == test[1]) || (touch.view == test[2]) || (touch.view == test[3])) {
[gestureRecognizer setCancelsTouchesInView:YES];
[swipeleft setCancelsTouchesInView:YES];
[gestureRecognizer setEnabled:NO];
[swipeleft setEnabled:NO];
return NO;
}
else
{
[gestureRecognizer setCancelsTouchesInView:NO];
[swipeleft setCancelsTouchesInView:NO];
[gestureRecognizer setEnabled:YES];
[swipeleft setEnabled:YES];
return YES;
}
}
我认为对你有用