2015-09-17 61 views
3

我需要執行一個不屑一顧的鍵盤(向下滑動忽略),就像iOS上股票消息應用程序中的那個一樣。不能移動鍵盤視圖iOS9 swift

我有這樣的代碼來獲取鍵盤觀點:

func keyboardWillShowWithNotification(notification:NSNotification) { 
    let keyboardView = accessoryView.superview 
} 

我連接的tableView的UIPanGestureRecognizer檢測什麼時候我需要開始向下移動鍵盤。

func handleTableViewPan(gr:UIPanGestureRecognizer) { 

    let location = panGestureRecognizer.locationInView(self.view) 
    let offset = ... //calculated correctly 
    keyboardView.frame.origin.y = originalKeyboardFrame.origin.y + offset 
} 

該方法適用於iOS 8,但與iOS 9似乎鍵盤保持不變,所以我不能移動它。 也許有人遇到同樣的問題,可以幫助我。 謝謝。

回答

5

在iOS 9中,有一個名爲UIRemoteKeyboardWindow的鍵盤的新窗口,因此當您使用accessoryView.superview時,您將看到錯誤的視圖。

爲了得到正確的觀點嘗試從窗口直接層次發現: (Objective-C代碼)

-(UIView*)getKeyboardInputView { 
    if([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) { 
     for(UIWindow* window in [[UIApplication sharedApplication] windows]) 
      if([window isKindOfClass:NSClassFromString(@"UIRemoteKeyboardWindow")]) 
       for(UIView* subView in window.subviews) 
        if([subView isKindOfClass:NSClassFromString(@"UIInputSetHostView")]) 
         for(UIView* subsubView in subView.subviews) 
          if([subsubView isKindOfClass:NSClassFromString(@"UIInputSetHostView")]) 
           return subsubView; 
    } else { 
     return accessoryView.superview; 
    } 
    return nil; 
} 

附:取自DAKeyboardControl https://github.com/danielamitay/DAKeyboardControl/pull/98

+0

感謝這幫了我。這會干擾應用提交嗎? – kevinl

+0

是的,它會的。這使用私有API,您冒着被拒絕的風險。 – DZenBot

相關問題