2014-10-04 31 views
4

我剛剛發佈了一個iOS 8更新到我的填字遊戲應用程序Four Down,並且已經開始接收報告,表明它進入了無法回答的狀態作爲敲擊鍵盤輸入而不是輸入字母。鍵盤在應用程序已經在後臺後沒有收到水龍頭

經過一番調查,只要應用程序放入背景中,然後再次變爲活動狀態,它就會可靠地進入此狀態。退出應用程序並重新啓動它可以解決問題,直到下一步從後臺返回。

發生問題時,由於鍵盤下方的視圖正在接收觸摸,因此觸摸檢測的順序出現錯誤(但不是視覺上)。我相信問題的具體iOS 8。

爲了診斷問題,我已經分類了UIApplication並重寫了sendEvent,以便我可以檢查發送的事件。當問題發生時,事件被分配給錯誤的UIWindow。下面是當它的工作情況:

2014-10-04 07:56:57.998 four-down[95709:8557144] <UITouchesEvent: 0x7fe838f07350> timestamp: 1.29014e+06 touches: {(
    <UITouch: 0x7fe83a11abf0> phase: Began tap count: 1 window: <UITextEffectsWindow: 0x7fe838d549e0; frame = (0 0; 320 568); opaque = NO; gestureRecognizers = <NSArray: 0x7fe838d556d0>; layer = <UIWindowLayer: 0x7fe838d54ea0>> view: <UIKeyboardLayoutStar: 0x7fe838da6a90; frame = (0 0; 320 216); opaque = NO; layer = <CALayer: 0x7fe838db3cc0>> location in window: {243, 388.5} previous location in window: {243, 388.5} location in view: {243, 36.5} previous location in view: {243, 36.5} 
)} 

而這裏的時候它不工作的情況下:

2014-10-04 07:58:08.952 four-down[95709:8557144] <UITouchesEvent: 0x7fe838f07350> timestamp: 1.29021e+06 touches: {(
    <UITouch: 0x7fe83a5c91a0> phase: Began tap count: 1 window: <UIWindow: 0x7fe83a33f3f0; frame = (0 0; 320 568); gestureRecognizers = <NSArray: 0x7fe83a340010>; layer = <UIWindowLayer: 0x7fe83a304160>> view: <CrosswordInteractiveView: 0x7fe83a555920; frame = (0 65; 310 310); gestureRecognizers = <NSArray: 0x7fe83a54d4e0>; layer = <CALayer: 0x7fe83a544df0>> location in window: {241.5, 379} previous location in window: {241.5, 379} location in view: {236.5, 250} previous location in view: {236.5, 250} 
)} 

注意對兩個事件的不同的窗口。 UITextEffectsWindow是包含鍵盤的窗口,UIWindow是主應用程序窗口。我檢查了每個窗口上的windowLevel屬性。在兩種情況下都是一樣的:鍵盤窗口爲1.0,主應用程序窗口爲0.0。

什麼,如果有的話,我做錯了嗎?鑑於它可以在iOS 7上運行,感覺就像是一個iOS bug,但是也許我應該調用一個新的iOS 8 API?如果沒有,我很樂意爲解決方法提供建議

+0

你有沒有找到這個答案?我遇到了同樣的問題! – gusbit 2015-07-06 16:57:16

+0

@gusbit不,但我想出了一個解決方法。我會把它作爲答案發布。希望能幫助到你。 – 2015-07-06 20:28:15

回答

2

我向蘋果提交了一個雷達(18546966)。他們將其作爲18406902的副本關閉。顯然,18406902已關閉,但這些都是我擁有的信息。不知道該修補程序將在哪個版本的iOS中進行。它可能會在iOS 9 beta版中修復 - 我還沒有對它進行測試。

在此期間,我想通了,它已經停止了錯誤報告以下解決方法:

- (UIView*) hitTest:(CGPoint) point withEvent:(UIEvent*) event { 
    UIView* hitView = [super hitTest:point withEvent:event]; 
    if (!hitView) { 
     UIWindow* keyboardWindow = [self findKeyboardWindow]; 
     if (keyboardWindow) { 
      UIView* viewInKeyboardWindow = [keyboardWindow hitTest:point withEvent:event]; 
      if (!viewInKeyboardWindow) { 
       [self resignFirstResponder]; 
      } else { 
       return viewInKeyboardWindow; 
      } 
     } else { 
      [self resignFirstResponder]; 
     } 
    } 
    return hitView; 
} 

- (UIWindow*) findKeyboardWindow { 
    NSArray* windows = [UIApplication sharedApplication].windows; 
    if (windows.count == 2) { 
     for (UIWindow* candidate in windows) { 
      if (candidate != self.window) { 
       return candidate; 
      } 
     } 
    } 
    return nil; 
} 
相關問題