2017-04-27 56 views
0

當鍵盤顯示時,UiTextView可以顯示選擇或光標。 我想隱藏鍵盤,並保持顯示選擇或光標的UiTextView(我在UiTextView下面顯示一個格式設置面板,並且希望通過格式面板修改textview的選擇格式,所以保持選擇textview顯示在需要)。uitextview無法在隱藏鍵盤後顯示選擇或光標

感謝〜

如果要隱藏鍵盤不僅沒有光標
+0

u能闡述更烏爾問題.....? –

+0

textView是可編輯的。軟鍵盤顯示單擊textView時,textView可以顯示選擇和光標。當「textview resignFirstResponder」被調用時,鍵盤解散,文本視圖結束編輯模式並停止顯示選擇或光標,但我需要的是textview在鍵盤解除後仍然顯示選擇或光標。 – Zero

回答

0

。試試下面的代碼:

for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) { 
     for (UIView *keyboard in [keyboardWindow subviews]) { 
      if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) { 

       keyboard.alpha = 0;// here change keyboard alpha 
      } 
     } 
} 

斯威夫特& IOS 10

let windows = UIApplication.shared.windows for window in windows { 
     if (NSStringFromClass(window.classForCoder) == "UIRemoteKeyboardWindow") { 
     let subViews = window.subviews if (subViews.count > 0) { subViews[0].alpha = 0 
     } 
    } 
} 
+0

感謝您的回答。但是「if([[keyboard description] hasPrefix:@」 0){ \t \t \t \t \t子視圖[0]。阿爾法= 0 \t \t \t \t} \t \t \t} \t \t} – Zero

+0

是您的解決方案是工作在IOS 10? – KKRocks

+0

讓窗口= UIApplication.shared.windows \t \t爲窗口中的窗口{ \t \t \t如果(** NSStringFromClass(window.classForCoder)== 「UIRemoteKeyboardWindow」 **){ \t \t \t \t讓子視圖=窗口。子視圖 \t \t \t \t如果(subViews.count> 0){ \t \t \t \t \t子視圖[0]。阿爾法= 0 \t \t \t \t} \t \t \t} \t \t} --------------------這確實工作!非常感謝。 – Zero