我可以在通知中传递手势识别器吗

can i Pass gesture recogniser in a notification

我正在从一个 class 向另一个发送通知以调用使用

的方法
[[NSNotificationCenter defaultCenter]
     postNotification:[
                       NSNotification notificationWithName:@"gestureIsOn"
                       object: self
                       ]
     ];

我想在这里实现的是在另一个 class 中接收通知,但也通过 UIGestureRecognizer 来查找它是哪个视图,因为接收通知的 class 包含 4 个不同的视图。我已经尝试过这样接收通知:

[[NSNotificationCenter defaultCenter ]addObserver:self
                                             selector:@selector(handleGestures::) name:@"gestureIsOn"
                                               object:nil];

并调用方法 handleGestures:

-(void)handleGestures:(UIGestureRecognizer *)sender :(NSNotification *)notification{

if(sender.view == view1)
do something

}

尝试在我的观察者通知中使用 double :: 但这会导致错误 Terminating app due to uncaught exception 'NSInvalidArgumentException'

提前感谢所有花时间阅读本文的人。

您可以这样发送:

[[NSNotificationCenter defaultCenter] postNotificationName:@"gestureIsOn"
                                                    object:self
                                                  userInfo:@{@"recognizer":recognizer}];

接收端:

UIGestureRecognizer *recognizer = notification.userInfo[@"recognizer"];