\编辑:现在委托使用手势识别器获取参数。
您只需实现协议,例如:
@protocol ViewControllerWithGestureRecognizerDelegate
- (void)viewControllerGestureRecognizerEvent:(UIPinchGestureRecognizer *)gestureRecognizer;
@end
在将要呈现手势识别器的视图控制器中,添加委托属性。
@property (nonatomic, weak) id<ViewControllerWithGestureRecognizerDelegate> delegate;
然后将手势识别器添加到您的视图控制器中:
UIPinchGestureRecognizer *gestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(gestureRecognizerAction:)];
[self addGestureRecognizer:gestureRecognizer];
在手势识别器的操作方法中调用委托方法:
- (void)gestureRecognizerAction:(UIPichGestureRecognizer *)gestureRecognizer
{
[self.delegate viewControllerGestureRecognizerEvent:gestureRecognizer];
}
在第二个视图控制器中(你想要在其中获得关于手势识别事件的通知),实现协议ViewControllerWithGestureRecognizerDelegate,并将手势识别器所在的视图控制器的委托设置为第二个视图控制器。请注意保留html标签。
ViewControllerWithGestureRecognizer.delegate = ViewControllerInWhichYouWantToGetNotifiedAboutGestureRecognizerEvents.
这样每次手势识别器调用其中一个视图控制器的方法时,第二个视图控制器都会得到通知。