IBDesignables and traitCollection in live rendering(实时渲染中的 IBDesignables 和 traitCollection)
问题描述
我正在构建我的自定义 UIControl,这是一个构建为 IBDesignable 的自定义按钮,它需要根据显示它的大小类进行更改.我有一个方法-setupForTraitCollection,它看起来像这样:
I am building my custom UIControl, a custom button built as an IBDesignable, which needs to change based on the size class in which it is being displayed. I have a method -setupForTraitCollection, which looks like this:
func setupForTraitCollection() {
switch(traitCollection.horizontalSizeClass, traitCollection.verticalSizeClass) {
case (.Regular, _):
// iPad - not compressed design
compressed = false
default:
// iPhone - compressed design
compressed = true
}
}
此代码在编译时运行良好,但在实时渲染中,以及在调试视图时,它永远不会碰到iPad"开关盒.我开始在这里放弃并简单地接受 traitCollections 在实时渲染中不可用,但我想确认这一点.更好的是,如果有人能指出我找到解决方案的方向.
This code works great when compiled, but in live rendering, and when debugging the view, it never hits the "iPad" switch case. I am starting to give up here and simply accept that traitCollections aren't available in live rendering, but I'd like to have this confirmed. Better still, if someone could point me in the direction of finding a solution.
所以最重要的问题是 - 我可以在 IBDesignable 中使用 traitCollections 吗?如果可以,如何使用?
So the to-the-point question is - Can I use traitCollections in an IBDesignable and if so, how?
我真的很希望能够在 IB 中更改大小类并在我的自定义控件上查看结果.
I'd really like to be able to change size class in IB and see the result on my custom control.
推荐答案
当我们在 Xcode 中渲染时,Interface Builder 尚未为可设计视图设置 trait 集合.我们正在使用radar://17278773 进行跟踪.在 http://bugreport.apple.com 提交报告并提及错误 ID 将帮助我们跟踪需求并确定优先级适当的.
Interface Builder does not yet set the trait collection for designable views when we are rendering in Xcode. We are tracking this with radar://17278773. Filing a report at http://bugreport.apple.com and mentioning that bug ID will help us track demand and prioritize appropriately.
这篇关于实时渲染中的 IBDesignables 和 traitCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:实时渲染中的 IBDesignables 和 traitCollection
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01