WWDC Auto Layout
WWDC 2012 V202
Add the constraint to the two views closest ancestors, every view is considered an acestor of itself.
E.g:
– Two siblings, add constraint to parent view.
– Cousins, constraint to grand parent
viewDidLoad – good place where to set the constraints
po [[UIWindow keywindo] _autolayoutTrace] to visualize the AutoLayout
setTranslatesAutorezingingMaskIntoConstraints -> If not using Auto Layout, Springs and masks are translated into AutoLayout.
WWDC 2012 V228
For debugging:
knowing what constraint is affecting
[view constraintsAffectingLayoutForAxis: NSLayoutCosntraintOrientationHorizontal/Vertical]
[view exerciseAmbiguitiInLayout]
Animation can be applied to the view or to the Auto Layout property
CoreAnimation:
1) Adjust constraints
2) [UIView animateWithDuration: 0.5 animations:^{
[view layoutIfNeeded];
}];
NSLayoutContraint:
changing the constant of a NSLayoutConstraint permits efficient relayouts
on iOS this can only be animated with NSTimer and on tick changing constraint.constant value
Alignment Rect:
Used to calculate the bounds to algin,doesn’t need to be the frame
Intrisinsic Content Size
Equivalency with sizeToFit, sizeThatFits
It is a preferred size, is not settable, constraint set them with their priorities
Any time the content changes so that the intrinsic content size should change-> [self invalidateIntrinsicContext]
Use intrinsicContentSize as a better sizeToFit
NSRect alignmentRect = (NSRect) {NSZeroPoint, [control intrinsicContentSize]};
[control setFrameSize: [control frameForAlignmentRect:alignmentRect].size];
Localisation
RTL
AutoLayout uses leading and trainling and they flip automatically on
WWDC 2012 V232 Autolayout By Example
Arguments:
NSDoubleLocalizedStrings YES: Multiplies all the strings by two to debug the Layout
Simulate right to left
AppleTextDirection YES
NSForceRightToLeftWritingDirection YES
Draw view alignment rects
UIViewShowAlignmentRects YES
Localizing RTL
If an asset is not desired to flip on language change… In IB set direction instead to Leading to Trailing, to the specific direction