Ios 要弃用的UIView自动布局方法的替代方法
根据UIView.h头文件,以下方法将被弃用 在代码中使用autolayout的替代方法是什么 我不知道代码注释中推荐的方法如何替换它们现有的对应方法,因为它们处理的是实际的约束,而不是UIView和约束之间的关系Ios 要弃用的UIView自动布局方法的替代方法,ios,swift,autolayout,deprecated,Ios,Swift,Autolayout,Deprecated,根据UIView.h头文件,以下方法将被弃用 在代码中使用autolayout的替代方法是什么 我不知道代码注释中推荐的方法如何替换它们现有的对应方法,因为它们处理的是实际的约束,而不是UIView和约束之间的关系 @interface UIView (UIConstraintBasedLayoutInstallingConstraints) - (NSArray *)constraints NS_AVAILABLE_IOS(6_0); - (void)addConstraint:(NSLa
@interface UIView (UIConstraintBasedLayoutInstallingConstraints)
- (NSArray *)constraints NS_AVAILABLE_IOS(6_0);
- (void)addConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided. Instead, set NSLayoutConstraint's active property to YES.
- (void)addConstraints:(NSArray *)constraints NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided. Instead use +[NSLayoutConstraint activateConstraints:].
- (void)removeConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided. Instead set NSLayoutConstraint's active property to NO.
- (void)removeConstraints:(NSArray *)constraints NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided. Instead use +[NSLayoutConstraint deactivateConstraints:].
@end
约束本身包含关系(即,它们指向关系中涉及的一个或多个视图),因此将约束添加到视图的旧方法是多余的,有时会令人困惑,因为必须在层次结构中选择正确的视图才能将其添加到 以新的方式,您只需创建约束并将其
活动
属性设置为是
(对于Objective-C)或真
(对于Swift),系统就会将其添加到正确的视图中。如果要添加多个约束,则调用类方法activateConstraints:
,它会为您设置属性
对于旧方法,由程序员向正确的视图添加约束。如果在涉及的视图a和视图B中有一个约束,则有3种可能在何处添加约束:
使用新方法,您只需将约束的
active
属性设置为YES/true
,系统就会为您解决这个问题。更简单。你说的“将它添加到正确的视图中”是什么意思?基于first/secondItem
属性的含义?正确的视图取决于两个视图在视图层次结构中的位置。如果视图B是视图a的子视图,它会将约束添加到视图a。如果视图a和B都是另一个视图的子视图,它会将约束添加到视图a和B的超级视图。有趣的是,这里有一个简短的文字供参考: