[英]uipangesturerecognizer with uiswipegesturerecognizer
Currently with panGesture the swiping isn't perfect. 目前使用panGesture刷卡并不完美。 If a user wants to swipe up but he goes one pixel to the right however the rest are up (user swipes up but ever so slightly goes to the right at the start), but the right will be activated and the up wouldn't. 如果用户想向上滑动,但他向右移了一个像素,但其余像素都向上(用户向上滑动,但在开始时稍微向右移了一点),但是向右将被激活,向上将不会被滑动。 I thought of integrating swipeGesture would minimise this sort of error, however it seems to not work. 我认为集成swipeGesture可以最大程度地减少此类错误,但是似乎不起作用。 I want it so when the user doesn't perfectly swipe Up at the start, up will still be activated and not left or right. 我想要这样,当用户在开始时没有完全向上滑动时,向上将仍然被激活,而不是向左或向右滑动。 It does work going up, down left or right but it's not 100% perfect as the user has to only change the y or x axis which is almost impossible. 它确实可以上下左右移动,但并不是100%完美,因为用户仅需更改y或x轴几乎是不可能的。
-(void)pan:(UIPanGestureRecognizer *)sender
{
CGPoint distance = [sender translationInView:self.view];
UISwipeGestureRecognizer *swiping;
[myImage addGestureRecognizer: swiping];
//Not Working
if(swiping.direction == UISwipeGestureRecognizerLeft || swiping.direction == UISwipeGestureRecognizerRight) {
NSLog(@"Verticle")
} else if(swiping.direction == UISwipeGestureRecognizerUp || swiping.direction == UISwipeGestureRecognizerDown) {
NSLog(@"Horizontal");
} else if(distance.x > 0 || distance.x < 0) { // From here down working but not perfect
NSLog(@"Verticle")
} else if (distance.y < 0 || distance.y > 0) {
NSLog(@"Horizontal")
}
[sender setTranslation:CGPointZero inView:self.view];
}
Rather than adding UISwipeGestureRecognizer, you could simply use an if statement. 与其添加UISwipeGestureRecognizer,不如直接使用if语句。 If they move by the x-coordinate 'by accident' first, you could run an if statement before saying it's vertical. 如果它们首先通过x坐标“偶然”移动,则可以运行if语句,然后说它是垂直的。 Change the 10 to you liking on the x-coordinate change. 您可以根据自己喜欢的x坐标更改更改10。
-(void)Pan: (UIPanGestureRecognizer *)sender
{
distance = [sender translationInView:self.view];
if (distance.x > 0 || distance.x < 0) {
if ((distance.y > 0 || distance.y < 0) && ((distance.x > 0 && distance.x < 10) || (distance.x < 0 && distance.x > -10))) {
NSLog(@"Horizontal");
} else {
NSLog(@"Verticle");
}
} else if (distance.y > 0 || distance.y < 0) {
NSLog(@"Starting Up Horizontal");
}
[sender setTranslation:CGPointZero inView:self.view];
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"Ended");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.