簡體   English   中英

uipangesturerecognizer與uispepegesturerecognizer

[英]uipangesturerecognizer with uiswipegesturerecognizer

目前使用panGesture刷卡並不完美。 如果用戶想向上滑動,但他向右移了一個像素,但其余像素都向上(用戶向上滑動,但在開始時稍微向右移了一點),但是向右將被激活,向上將不會被滑動。 我認為集成swipeGesture可以最大程度地減少此類錯誤,但是似乎不起作用。 我想要這樣,當用戶在開始時沒有完全向上滑動時,向上將仍然被激活,而不是向左或向右滑動。 它確實可以上下左右移動,但並不是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];
}

與其添加UISwipeGestureRecognizer,不如直接使用if語句。 如果它們首先通過x坐標“偶然”移動,則可以運行if語句,然后說它是垂直的。 您可以根據自己喜歡的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM