【问题标题】:Change UITextView Keyboard Appearance globally in app delegate在应用委托中全局更改 UITextView 键盘外观
【发布时间】:2021-03-24 23:40:17
【问题描述】:

我已经看到 UITextField 的答案,但我似乎无法在应用程序委托中为 UITextView 更改 keyboardAppearance 找到明确的答案。这甚至可能吗?

UITextView.appearance().keyboardAppearance = .dark

导致崩溃

【问题讨论】:

  • 你在做什么有什么问题?
  • 我的应用程序中有自定义暗/亮模式,所以我想从我的应用程序委托中同时更改所有 UITextViews 键盘外观。当我使用上面的代码时,我的应用程序会崩溃。
  • 什么崩溃?

标签: swift uikit


【解决方案1】:

我正在经历同样的不良行为。

在 didFinishLaunchingWithOptions 中放置后:

UITextView.appearance().keyboardAppearance = .dark

一旦 UITextView 必须出现在屏幕上,就会触发下一个错误:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Have you sent -setKeyboardAppearance: to <UITextView: 0x7ff31113e000; frame = (0 0; 0 0); text = '"Enter an optional commen...'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x60000209fb10>; layer = <CALayer: 0x600002ecc740>; contentOffset: {0, 0}; contentSize: {0, 37}; adjustedContentInset: {0, 0, 0, 0}> off the main thread? To verify, look for a complaint in the logs: "Unsupported use of UIKit…", and fix the problem if you find it. If your use is main-thread only please file a radar on UIKit, and attach this log. exercisedImplementations = {
    "setKeyboardAppearance:" =     (
    );
}'

这很奇怪,因为 UITextView 遵循 UITextInputTraits 协议,它允许我们定义默认键盘外观。

任何帮助将不胜感激。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    相关资源
    最近更新 更多