如何获得触摸视图的UIViewController的引用?UIGestureRecognizer - 获取对触摸的UIViewController的引用,而不是其视图?
我在UIViewController的视图上使用UIPanGestureRecognizer。以下是我初始化:
TaskUIViewController *thisTaskController = [[TaskUIViewController alloc]init];
[[self view]addSubview:[thisTaskController view]];
UIPanGestureRecognizer *panRec = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[[thisTaskController view] addGestureRecognizer:panRec];
在tiggered动作使用手势识别我能够得到从参数角度触发使用recognizer.view
- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {
UIView *touchedView = [[UIView alloc]init];
touchedView = (UIView*)[recognizer view];
...
}
但是我真正需要的是触摸视图的底层UIViewController。我如何获得对包含此视图而不是仅UIView的UIViewController的引用?
非常感谢。你写的东西对我来说很有意义。但是,使用UIViewController中的GesturerRecognizer,只要我用“EXC_BAD_ACCESS ...”错误触发pan事件,程序就会崩溃。不幸的是没有提供关于原因的更多提示。对此有何想法? – Bernd 2012-07-29 22:02:50
只需检查您是否在手势中设置了正确的目标以及正确的处理程序。没有魔法,只是一个代码:) – SVGreg 2012-07-29 22:09:10
我做到了,因为你提出了“UIPanGestureRecognizer * panRec = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan :)];”所有这些都在UIViewController的viewDidLoad方法中。 “handlePan”方法也存在...令人费解 – Bernd 2012-07-30 08:52:17