当用户单击屏幕时,我想在两个类(超级视图和全屏子视图)中调用操作。但是,当我向子视图添加 UITapGestureRecognizer 时,添加到超级视图的 UITapGestureRecognizer 将被覆盖。是否可以将 UITapGestureRecognizer 添加到子视图而不覆盖添加到超级视图的 UITapGestureRecognizer?
如果是这样,我该怎么做?
Thanks!
Edit:从我的主视图控制器“MyToolBerController”中,我从另一个视图控制器添加子视图,如下所示:
PhotoViewController *photoViewController = [[PhotoViewController alloc] initWithNibName:@"PhotoViewController" bundle:nil];
myPhotoView = photoViewController.view;
[self.view addSubview:myPhotoView];
我在 MyToolBerController 中添加 GestureRecognizer,如下所示:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom:)];
[singleTap setNumberOfTapsRequired:1];
singleTap.delegate = self;
[myPhotoView addGestureRecognizer:singleTap];
[singleTap release];
这一切都工作正常,但我需要在点击视图时调用 PhotoViewController 类中的方法以及 MyToolBerController 类中的方法。
当我在 photoViewController 中添加另一个 UITapGestureRecognizer 时,它会覆盖 superView 中添加的 UITapGestureRecognizer。
当手势发生时,手势识别器可以调度多个动作。您可以将子视图添加为手势识别器的另一个目标,并且仅使用单个 UITapGestureRecognizer 实例:
[tapRecognizer addTarget:theSubview action:@selector(whatever:)];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)