实时渲染中的 IBDesignables 和 traitCollection

IBDesignables and traitCollection in live rendering(实时渲染中的 IBDesignables 和 traitCollection)

本文介绍了实时渲染中的 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

基础教程推荐