第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

按下時會兩次調(diào)用UILongPressGestureRecognizer

按下時會兩次調(diào)用UILongPressGestureRecognizer

翻閱古今 2019-10-23 16:14:49
我正在檢測用戶是否已按下2秒鐘:UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]                                             initWithTarget:self                                              action:@selector(handleLongPress:)];        longPress.minimumPressDuration = 2.0;        [self addGestureRecognizer:longPress];        [longPress release];這是我處理長按的方式:-(void)handleLongPress:(UILongPressGestureRecognizer*)recognizer{    NSLog(@"double oo");}當(dāng)我按下2秒鐘以上時,文本“ double oo”被打印兩次。為什么是這樣?我該如何解決?
查看完整描述

3 回答

?
海綿寶寶撒

TA貢獻(xiàn)1809條經(jīng)驗 獲得超8個贊

UILongPressGestureRecognizer是連續(xù)事件識別器。您必須查看狀態(tài)以查看這是事件的開始,中間還是結(jié)束,并采取相應(yīng)的措施。即,您可以在開始之后放棄所有事件,或者僅根據(jù)需要查看運動。從 類參考:


長按手勢是連續(xù)的。當(dāng)在指定時間段內(nèi)(minimumPressDuration)按下了允許的手指數(shù)(numberOfTouchesRequired),并且觸摸沒有移動超出允許的移動范圍(allowableMovement)時,手勢即開始(UIGestureRecognizerStateBegan)。每當(dāng)手指移動時,手勢識別器都會轉(zhuǎn)換為“更改”狀態(tài),并且在任何手指抬起時手勢識別器都會終止(UIGestureRecognizerStateEnded)。


現(xiàn)在您可以像這樣跟蹤狀態(tài)


-  (void)handleLongPress:(UILongPressGestureRecognizer*)sender { 

    if (sender.state == UIGestureRecognizerStateEnded) {

      NSLog(@"UIGestureRecognizerStateEnded");

    //Do Whatever You want on End of Gesture

     }

    else if (sender.state == UIGestureRecognizerStateBegan){

       NSLog(@"UIGestureRecognizerStateBegan.");

   //Do Whatever You want on Began of Gesture

     }

  }


查看完整回答
反對 回復(fù) 2019-10-23
?
白板的微信

TA貢獻(xiàn)1883條經(jīng)驗 獲得超3個贊

要檢查UILongPressGestureRecognizer的狀態(tài),只需在選擇器方法上添加if語句:


- (void)handleLongPress:(UILongPressGestureRecognizer *)sender {    

    if (sender.state == UIGestureRecognizerStateEnded) {

        NSLog(@"Long press Ended");

    } else if (sender.state == UIGestureRecognizerStateBegan) {

        NSLog(@"Long press detected.");

    }

}


查看完整回答
反對 回復(fù) 2019-10-23
?
達(dá)令說

TA貢獻(xiàn)1821條經(jīng)驗 獲得超6個贊

您需要檢查正確的狀態(tài),因為每種狀態(tài)都有不同的行為。您最有可能需要UIGestureRecognizerStateBegan帶有狀態(tài)UILongPressGestureRecognizer。


UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]

                                             initWithTarget:self 

                                             action:@selector(handleLongPress:)];

longPress.minimumPressDuration = 1.0;

[myView addGestureRecognizer:longPress];

[longPress release];

...


- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture {

    if(UIGestureRecognizerStateBegan == gesture.state) {

        // Called on start of gesture, do work here

    }


    if(UIGestureRecognizerStateChanged == gesture.state) {

        // Do repeated work here (repeats continuously) while finger is down

    }


    if(UIGestureRecognizerStateEnded == gesture.state) {

        // Do end work here when finger is lifted

    }

}


查看完整回答
反對 回復(fù) 2019-10-23
  • 3 回答
  • 0 關(guān)注
  • 946 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號