添加为subview ios sdk时滑动手势不起作用

时间:2013-02-11 16:02:38

标签: ios ipad uigesturerecognizer subview

我花了整个周末试图弄清楚为什么我的手势不起作用。当我作为模型视图呈现时,手势正在工作,但当我添加为子视图时,手势无法正常工作。是否有任何理由只有在作为子视图添加时才能正常工作。

此代码有效:

myVC = [[FullViewController alloc] initWithNibName:@"FullViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: myVC];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:navigationController animated:YES];
navigationController.view.superview.bounds = CGRectMake(0,0,1024,724);

此代码不起作用:

myVC = [[FullViewController alloc] initWithNibName:@"FullViewController" bundle:nil];
myVC.view.frame = CGRectMake(0, 0, 1024, 724);
myNavCtrl = [[UINavigationController alloc] initWithRootViewController:myVC];
[self.view addSubview: myNavCtrl.view];
myNavCtrl.view.frame = CGRectMake(0, -20, 1024, 675);

手势识别码:

swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.view addGestureRecognizer:swipeLeft];

任何帮助都是学徒。

2 个答案:

答案 0 :(得分:0)

在我看来,superview不允许触摸或用户交互。无法确切地说明为什么使用您提供的代码片段,但您可以尝试向超级视图添加手势识别器,看看是否有效,如果没有,则问题出在superview上。

它可以作为模态,因为它根本不使用其他视图。

答案 1 :(得分:0)

没有看到handleSwipeLeft细节:

看起来您正在设置UIGestureRecognizer并告诉它调用选择器/方法:handleSwipeLeft。

您应该在View Controller中声明UIGestureRecognizer,但是将目标设置为UIView子类,然后在UIView子类中实现handleSwipeLeft。

希望有效

相关问题