【问题标题】:iOS 8.3 'UIView-Encapsulated-Layout-Width' in Custom Keyboard自定义键盘中的 iOS 8.3 'UIView-Encapsulated-Layout-Width'
【发布时间】:2015-06-16 09:35:56
【问题描述】:

我已经实现了一个自定义键盘。它在运行 iOS 8.2 的设备上运行良好。

但是,当我在装有 iOS 8.3 的设备上运行相同的代码时,我收到以下警告,并且键盘的高度设置不正确:

Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x15dd1da0 h=-&- v=-&- Keyboard:0x15db2b00.width == UIView:0x15da7b90.width - 320>",
    "<NSLayoutConstraint:0x15dd2520 'UIView-Encapsulated-Layout-Width' H:[UIView:0x15da7b90(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x15dd2520 'UIView-Encapsulated-Layout-Width' H:[UIView:0x15da7b90(0)]>

我不知道这意味着什么。请帮我弄清楚。

【问题讨论】:

  • 我实际上在 8.2 设备上看到了此消息,根据我的经验,它实际上表明您的约束 得到遵守并且您的高度已正确设置。您在 8.3 设备上仍然拥有完全访问权限吗? UIInputView 中还有其他带有自动布局约束的视图吗?
  • @BenPious 不幸的是高度也没有正确设置。

标签: objective-c ios8 autolayout custom-keyboard


【解决方案1】:
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x15dd1da0 h=-&- v=-&- Keyboard:0x15db2b00.width == UIView:0x15da7b90.width - 320>",
    "<NSLayoutConstraint:0x15dd2520 'UIView-Encapsulated-Layout-Width' H:[UIView:0x15da7b90(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x15dd2520 'UIView-Encapsulated-Layout-Width' H:[UIView:0x15da7b90(0)]>

它告诉你它不能同时满足所有约束。

您有一个约束&lt;NSAutoresizingMaskLayoutConstraint:0x15dd1da0 h=-&amp;- v=-&amp;- Keyboard:0x15db2b00.width == UIView:0x15da7b90.width - 320&gt;,它规定键盘的宽度等于UIView0x15da7b90 的宽度减去320(检查调试器这是哪一个,如果我我通常会查看GUI 调试器知道UIViews 可能导致问题的原因)。

另一个冲突的约束是&lt;NSLayoutConstraint:0x15dd2520 'UIView-Encapsulated-Layout-Width' H:[UIView:0x15da7b90(0)]&gt;,它规定UIView0x15da7b90(同一个)的宽度为0。它不能同时满足这个和上面的一个,所以它打破了这个。

我看到您的第一个约束是 NSAutoresizingMaskLayoutConstraint 类型之一,因此您可以尝试在视图上将 setTranslatesAutoresizingMaskIntoConstraints 设置为 false,这可能会删除第一个约束,从而消除冲突。

其他有用的文档:

【讨论】:

    【解决方案2】:

    我在做键盘扩展的时候也有过这样的经历。

    也就是说UIInputViewControllerinputView对inputView的parentView有UIViewAutoresizingFlexible

    并且掩码被翻译成封装的约束,名称为

    <NSLayoutConstraint:0x15dd2520 'UIView-Encapsulated-Layout-Width' H:[UIView:0x15da7b90(0)]>
    

    在您的日志中,还有另一个已翻译的约束(来自屏蔽),所以我认为您可以使用它轻松管理视图。在我看来,你必须使用 NSConstraint(width and height ...)

    我曾尝试从 inputView 中移除遮罩,但它在管理位置和边界方面给我带来了更多困难。

    另外,我在旧版应用程序上运行键盘时遇到了这种情况(iPhone 6/6+ 不支持)。

    每次我旋转屏幕时,关于高度的限制都会被像你这样的日志阻止。

    如果您还有其他问题或我的回答不够充分,请再次告诉我。

    【讨论】:

    • 还是像collectionview一样向inputView添加自动屏蔽视图?
    【解决方案3】:

    NSAutoresizingMaskLayoutConstrain 这意味着您没有正确设置自动布局约束。尝试正确设置它,您的问题将得到解决

    【讨论】:

      猜你喜欢
      • 2021-01-14
      • 2015-10-09
      • 2014-02-05
      • 2017-02-01
      • 2021-09-01
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      • 2015-04-09
      相关资源
      最近更新 更多