簡體   English   中英

點擊手勢識別器太慢

[英]Tap Gesture Recognizer too slow

我很難獲得UITapGestureRecognizer來檢測正在發生的每個點擊。 對於上下文,我正在制作鼓點應用程序。 我已經讓水龍頭手勢識別器正常工作,但是用戶應該能夠非常快速地敲擊鼓,並且識別器只是輕輕一點,所以經常使用水龍頭(如果你試圖盡可能快地點擊) )。

我猜這與iOS分類連續快速分類作為一個手勢有關,但有沒有辦法讓每次手指下來作為點擊事件?

我嘗試過使用UILongPressGestureRecognizerUILongPressGestureRecognizer時間很短。

我嘗試將requiredNumberofTouchesrequiredNumberofTaps設置為1。

為了回答這個問題,似乎沒有必要發布代碼,但如果您提出要求,我會發布。

非常感激任何的幫助!

編輯:我正在添加我的代碼,因為它可能會有所幫助:

-(void)tap:(UITapGestureRecognizer *)tapGestureRecognizer {

    CGPoint location = [tapGestureRecognizer locationInView:[self view]];

    switch ([self validateTouchLocation:location]) {
        case 0:
            return;
        case 1:
            [[ASSoundManager sharedManager] playSoundNamed:@"SD0025" ofType:@"mp3"];
            break;
        case 2:
        default:
            [[ASSoundManager sharedManager] playSoundNamed:@"SD0010" ofType:@"mp3"];
            break;
    }

    float tapWidth = 30;
    ASDrumTapView *drumTapView = [[ASDrumTapView alloc] initWithFrame:CGRectMake(location.x - (tapWidth / 2), location.y - (tapWidth / 2), tapWidth, tapWidth)];
    [drumTapView setBackgroundColor:[UIColor clearColor]];
    [drumTapView setNeedsDisplay];
    [[self view] addSubview:drumTapView];

    float animDuration = 0.75;
    CGRect frame = [drumTapView frame];

    [UIView animateKeyframesWithDuration:animDuration
                                   delay:0.0
                                 options:0
                              animations:^{
                                  [UIView addKeyframeWithRelativeStartTime:0
                                                          relativeDuration:animDuration
                                                                animations:^{
                                                                    [drumTapView setFrame:CGRectInset(frame, -frame.size.width, -frame.size.height)];
                                                                }];
                                  [UIView addKeyframeWithRelativeStartTime:0
                                                          relativeDuration:3*animDuration/5
                                                                animations:^{
                                                                    [[drumTapView layer] setOpacity:0.0];
                                                                }];
                              }
                              completion:^(BOOL finished) {
                                  [drumTapView removeFromSuperview];
                              }];
}

可能有很多原因:

  • 一個可能的原因可能是您的音頻引擎在上一個聲音完成之前無法播放下一個聲音。
  • 檢查UIView multipleTouchEnabled屬性
  • 如果您的視圖嵌入在UIScrollView或任何派生類中,請檢查delaysContentTouches屬性

雖然我很欣賞每個人的意見,但我自己也想到了。

在我的代碼中,我正在運行一個關鍵幀動畫,其選項設置為0 這意味着在動畫期間,用戶與視圖的交互未啟用。

通過將options設置為UIKeyframeAnimationOptionAllowUserInteraction ,即使其中一個子視圖仍處於動畫UIKeyframeAnimationOptionAllowUserInteraction ,我也可以選擇點擊。

希望這有助於其他人!

暫無
暫無

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

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