如何知道当前大小 类 以及我的按钮是否显示?
How to know the current size classes and if my button is displayed?
我在我的项目中使用尺寸 类。
我有一个按钮,只显示
- 压缩宽度和压缩高度
- 紧凑宽度和常规高度
其他尺码不显示此按钮 类。
我在这个按钮上应用了特定的效果。但我只需要为我的 2 个尺寸应用此效果 类。
类似于:
if button is available for the current size classe
apply the effect
是否可以实现?
为了跟进我现在已删除的先前回答和后续评论,Apple's docs state
A runtime object for an uninstalled view is still created. However, the view and any related constraints are not added to the view hierarchy and the view has a superview property of nil. This is different from being hidden. A hidden view is in the view hierarchy along as are any related constraints.
换句话说,唯一知道的方法是检查出口视图的父视图是否是nil
。
在 ViewWillApper() 期间检查视图控制器的 traitCollection。
myViewController: UIViewController{
mybutton = UIButton(frame: myframe)
func viewWillAppear(){
if traitCollection.horizontalSizeClass == .Compact {
applyAwesomeEffect(myButton)
}
}
}
我在我的项目中使用尺寸 类。
我有一个按钮,只显示
- 压缩宽度和压缩高度
- 紧凑宽度和常规高度
其他尺码不显示此按钮 类。
我在这个按钮上应用了特定的效果。但我只需要为我的 2 个尺寸应用此效果 类。
类似于:
if button is available for the current size classe
apply the effect
是否可以实现?
为了跟进我现在已删除的先前回答和后续评论,Apple's docs state
A runtime object for an uninstalled view is still created. However, the view and any related constraints are not added to the view hierarchy and the view has a superview property of nil. This is different from being hidden. A hidden view is in the view hierarchy along as are any related constraints.
换句话说,唯一知道的方法是检查出口视图的父视图是否是nil
。
在 ViewWillApper() 期间检查视图控制器的 traitCollection。
myViewController: UIViewController{
mybutton = UIButton(frame: myframe)
func viewWillAppear(){
if traitCollection.horizontalSizeClass == .Compact {
applyAwesomeEffect(myButton)
}
}
}