2016-11-13 97 views
0

就像標題所說,當我更新Xcode8時,在我的項目中,長按手勢很容易被觸發,即使當我點擊屏幕時,它也會調用!鍵盤也有這個問題。當我輸入一個字,Xcode的打印信息來源象如下:iOS項目:爲什麼長按手勢很容易被觸發?

[UIWindow endDisablingInterfaceAutorotationAnimated:] called on <UIRemoteKeyboardWindow: 0x100ffb940; frame = (0 0; 414 736); opaque = NO; autoresize = W+H; layer = <UIWindowLayer: 0x17042d700>> without matching -beginDisablingInterfaceAutorotation. Ignoring. 

並在視圖中,我添加了一個輕拍姿態和長按手勢,當我點擊(剛剛接觸),手勢觸發時長按,而不是挖掘手勢。這個問題我沒有找到任何地方,所以我來這裏問你的幫助。 (原諒我,這對我的英語來說太可怕了)

我發佈兩張照片給你可以清楚地知道。

keyboard

textview

這是我的代碼:

UILongPressGestureRecognizer * lp = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(lp:)]; 
lp.minimumPressDuration = 1.0f; 
[_imageView addGestureRecognizer:lp]; 
- (void)lp:(UILongPressGestureRecognizer*)lp { 
    if (lp.state == UIGestureRecognizerStateBegan) { 
     if (self.delegate && [self.delegate respondsToSelector:@selector(longPressImage)]) { 
      [self.delegate longPressImage]; 
     } 
    } 
} 

此外,此問題在某些設備上happend,並不是所有的devices.One設備始終happend,其他人只是happend某個時候,當我再次建立項目,它只是OKO__O「...

+0

請張貼代碼。 – shallowThought

+0

對不起,但很難理解這個問題。 – Eiko

+0

用相關代碼更新您的問題,顯示您如何創建和設置長按手勢以及如何處理其事件。 – rmaddy

回答

0

你應該檢查UIGestureRecognizerStateEnded而不是UIGestureRecognizerStateBegan。當觸摸被識別爲某個手勢的開始時,觸發UIGestureRecognizerStateBegan。這個手勢不是你需要的長按。只有在識別器狀態更改爲UIGestureRecognizerStateEnded時,纔會按照您的期望執行長按操作。

- (void)lp:(UILongPressGestureRecognizer*)lp { 
    if (lp.state == UIGestureRecognizerStateEnded) { 
     if (self.delegate && [self.delegate respondsToSelector:@selector(longPressImage)]) { 
      [self.delegate longPressImage]; 
     } 
    } 
} 
+0

感謝您的回答。但我認爲這不是解決方案,我嘗試了這一點,但它不起作用。在我看來,手勢不是原因,可能是我在某處使用某個運行時的原因。無論如何,謝謝! –