簡體   English   中英

iOS - Gesture Recognizer translationInView

[英]iOS - Gesture Recognizer translationInView

我在平移手勢識別器中使用以下代碼行:

CGPoint translation = [sender translationInView:self.view];

如果我將關聯的處理移動到長按手勢識別器,則沒有translateInView方法。

我的問題是,如果使用長按識別器,如何獲得相同的翻譯價值?

謝謝

CGPoint location = [recognizer locationInView:self.view];

對於UILongPressgestureRecognizerv,它不在視圖中進行翻譯,它是locationInView。

-(void)handleLongPress:(UILongPressGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:self.view];

switch (recognizer.state) {
    case UIGestureRecognizerStateBegan:
        break;
    case UIGestureRecognizerStateChanged:
        break;
    case UIGestureRecognizerStateEnded:
        break;
    default:
        break;
    }   
}

希望它會對你有所幫助。

感謝您的回復。 我真正想要的是translateInView的計算,它與locationInView不同。 我用以下代碼解決了這個問題:

CGPoint location = [sender locationInView:self.view];
CGPoint translation;
translation.x = location.x - viewStartLocation.x;
translation.y = location.y - viewStartLocation.y;

它確實需要我跟蹤起始位置,這與平移手勢識別器沒有關系,但它似乎運行良好。 我的其余代碼以轉換而不是位置為中心,所以我試圖避免為了一致性而重寫其他代碼。

再次感謝您花時間回復。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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