iOS Touch事件不響應(yīng)的一種情況

今天遇見了一件很詭異的情況,在真機(jī)上調(diào)試發(fā)現(xiàn)點(diǎn)擊UIView的時候會出現(xiàn)選中狀態(tài)未更新的問題,打了斷點(diǎn)后發(fā)現(xiàn)邏輯又是正常的,每次點(diǎn)擊都會進(jìn)入響應(yīng)事件的方法,然后初步把bug定位在UI的更新阻礙了事件的響應(yīng),在touch事件分別打了斷點(diǎn)逐步查看:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self setBackgroundColor:[UIColor colorWithRed:0.969 green:0.969 blue:0.969 alpha:1]];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[self setBackgroundColor:[UIColor whiteColor]];
}

- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
NSLog(@"????????????");
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self setBackgroundColor:[UIColor whiteColor]];
if (self.editable) {
    [self switchSelectMode];
}
if(_clickTargetObj && _clickTargetAction && [_clickTargetObj respondsToSelector:_clickTargetAction]){
    [self setBackgroundColor:[UIColor colorWithRed:0.969 green:0.969 blue:0.969 alpha:1]];
    [_clickTargetObj performSelector:_clickTargetAction withObject:self];
    
    __weak UIBaseFileListView *me = self;
    [UIView animateWithDuration:0.1f animations:^{
        [me setBackgroundColor:[UIColor whiteColor]];
    } completion:^(BOOL finished) {
    }];
}

結(jié)果發(fā)現(xiàn)在頻繁點(diǎn)擊的時候連touchBegin事件都沒有響應(yīng),然后檢查代碼,發(fā)現(xiàn)在注釋掉[UIView animateWith...]的動畫后正常了。
感覺是UIView在執(zhí)行動畫的時候會屏蔽掉touch事件,默認(rèn)把userInteractionEnabled改為false

更新

查了下SDK,在userInteractionEnabled的文檔里有提到這個問題:

During an animation, user interactions are temporarily disabled for all views involved in the animation, regardless of the value in this property. You can disable this behavior by specifying theUIViewAnimationOptionAllowUserInteraction
option when configuring the animation.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 好奇觸摸事件是如何從屏幕轉(zhuǎn)移到APP內(nèi)的?困惑于Cell怎么突然不能點(diǎn)擊了?糾結(jié)于如何實(shí)現(xiàn)這個奇葩響應(yīng)需求?亦或是...
    Lotheve閱讀 59,473評論 51 604
  • 在iOS開發(fā)中經(jīng)常會涉及到觸摸事件。本想自己總結(jié)一下,但是遇到了這篇文章,感覺總結(jié)的已經(jīng)很到位,特此轉(zhuǎn)載。作者:L...
    WQ_UESTC閱讀 6,237評論 4 26
  • 本文來自:http://ios.jobbole.com/84081/ 前言: 按照時間順序,事件的生命周期是這樣的...
    HackerOnce閱讀 2,943評論 1 10
  • 趙炎被徹底的孤立了,也就意味徹底“臭了”。大家不愿意與他扯上任何關(guān)系。 “你同事趙炎怎么回事?”有人問黃華安。 “...
    ZHANG頑石點(diǎn)頭閱讀 192評論 0 0
  • 情感書寫于筆下 成了情詩 情感譜寫成曲調(diào) 有了情歌 情感久駐回憶 充滿滄桑 情感拋向空中 隨風(fēng)流浪 如果人生是用來...
    Soulhome閱讀 288評論 11 1

友情鏈接更多精彩內(nèi)容