according uiview.h header file, methods below deprecated.
what alternative way of working autolayout in code?
i don't see how methods recommended in code comment replace existing counterparts work on actual constraint , not on relation between uiview , constraint.
@interface uiview (uiconstraintbasedlayoutinstallingconstraints) - (nsarray *)constraints ns_available_ios(6_0); - (void)addconstraint:(nslayoutconstraint *)constraint ns_available_ios(6_0); // method deprecated in future release , should avoided. instead, set nslayoutconstraint's active property yes. - (void)addconstraints:(nsarray *)constraints ns_available_ios(6_0); // method deprecated in future release , should avoided. instead use +[nslayoutconstraint activateconstraints:]. - (void)removeconstraint:(nslayoutconstraint *)constraint ns_available_ios(6_0); // method deprecated in future release , should avoided. instead set nslayoutconstraint's active property no. - (void)removeconstraints:(nsarray *)constraints ns_available_ios(6_0); // method deprecated in future release , should avoided. instead use +[nslayoutconstraint deactivateconstraints:]. @end
the constraints contain relation (that is, point view or views involved in relation), old way of adding constraints view redundant , confusing because had choose right view in hierarchy add them to.
in new way, create constraints , set active
property yes
(for objective-c) or true
(for swift) , system adds correct view you. if have more 1 constraint add, call class method activateconstraints:
, sets property you.
with old method, programmer add constraints correct view. if had constraint involved view , view b, there 3 possibilities of add constraint:
- if view subview of view b (or subview of subview), constraint should added view b.
- if view b subview of view (or subview of subview), constraint should added view a.
- if view , view b both subviews of view (call c), constraint should added view c.
with new method, set constraint's active
property yes/true
, system figures out you. it's easier.