简体   繁体   English

如何从UIView中除去手势识别器的一部分?

[英]How can I except a part from a UIView for a gesture recognizer?

I am developing an app and I want to scroll through different UIViewControllers with a UISwipeGestureRecognizer . 我正在开发一个应用程序,我想使用UISwipeGestureRecognizer滚动浏览不同的UIViewControllers Everything works, but there is one thing where I couldn't find a solution for. 一切正常,但是有一件事我找不到解决方案。

I add the UIGestureRecognizers like this 我这样添加UIGestureRecognizers

- (void)viewDidLoad {
[super viewDidLoad];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.view addGestureRecognizer:swipeLeft];

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight)];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[self.view addGestureRecognizer:swipeRight];
}

Now I want to know if it is possible to except a part of the self.view where it is possible to swipe to a different view. 现在,我想知道是否有可能在self.view的一部分之外滑动到其他视图。 I want to do this around a UISwitch . 我想围绕UISwitch做到这一点。

Can someone please help me? 有人可以帮帮我吗?

Best regards, 最好的祝福,

Lukas Goes 卢卡斯去

You can use another UIView and add it to self.view . 您可以使用另一个UIView并将其添加到self.view Those UISwipeGestureRecognizer won't work inside that UIView . 那些UISwipeGestureRecognizer将无法在该UIView

Add another UISwipeGestureRecognizer to the switch, and, on your original swipe gesture recognisers, call requireGestureRecognizerToFail: on the switch's new recognizer. 将另一个UISwipeGestureRecognizer添加到开关,然后在原始的滑动手势识别器上,在开关的新识别器上调用requireGestureRecognizerToFail:

Hope that makes sense, it's such a verbose class... :\\ 希望有道理,这是一个冗长的类...:\\

I suggest you to use the delegate method of a gesture recognizer : gestureRecognizer:shouldReceiveTouch: . 我建议您使用手势识别器的委托方法: gestureRecognizer:shouldReceiveTouch: In the touch parameter, you have many information, like the position in the screen. touch参数中,您有许多信息,例如屏幕上的位置。 You can use this position and test if it is above the switch frame. 您可以使用此位置并测试它是否在开关框上方。 Return yes or no depending of if you want to trigger the selector associated to the gesture recognizer or not. 根据是否要触发与手势识别器关联的选择器,返回yesno

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM