簡體   English   中英

應用程序處於后台后,鍵盤不會收到點按

[英]Keyboard doesn't receive taps after app has been in the background

我剛剛向我的填字游戲應用程序Four Down發送了一個iOS 8更新,並且已經開始接收報告,它進入一個無法輸入答案的狀態,因為點擊鍵盤會解除它而不是輸入一個字母。

經過一些調查后,只要應用程序進入后台,它就會可靠地進入此狀態,然后再次變為活動狀態。 退出應用程序並重新啟動它可以解決問題,直到下一次從后台返回。

當問題發生時,看起來事物以錯誤的順序堆疊以進行觸摸檢測(但不是視覺上),因為鍵盤下方的視覺接收觸摸。 我相信問題的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錯誤,但也許我應該調用一個新的iOS 8 API? 如果沒有,我會歡迎有關解決方法的建議

我向Apple提交了一個雷達(18546966)。 他們把它作為18406902的副本關閉了。顯然,18406902已經關閉,但這就是我所擁有的所有信息。 不知道該修補程序將在哪個版本的iOS中。它可以在iOS 9測試版中修復 - 我還沒有測試過它。

與此同時,我想出了以下解決方法,它已經停止了錯誤報告:

- (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;
}

暫無
暫無

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

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