LK_*_*K__ 9 deprecated ios autolayout swift
根据UIView.h头文件,以下方法将被弃用.
在代码中使用autolayout的替代方法是什么?
我没有看到代码注释中推荐的方法如何替换它们现有的对应物,因为它们处理实际约束而不是UIView和约束之间的关系.
@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
Run Code Online (Sandbox Code Playgroud)
约束本身包含关系(即,它们指向关系中涉及的视图或视图),因此将约束添加到视图的旧方法是多余的,有时会令人困惑,因为您必须在层次结构中选择正确的视图将它们添加到.
在新方法中,您只需创建约束并将其active属性设置为YES(对于Objective-C)或true(对于Swift),系统会将其添加到正确的视图中.如果要添加多个约束,则调用类方法activateConstraints:并为其设置属性.
使用旧方法,程序员可以将约束添加到正确的视图中.如果你有一个约束所涉及的视图A和视图B,那么有3种可能性来添加约束:
使用新方法,您只需将约束的active属性设置为YES/true,系统就会为您计算出来.这更容易.
| 归档时间: |
|
| 查看次数: |
1391 次 |
| 最近记录: |