Xcode Interface Builder. How Do These Autosizing Mask Settings Differ?
I am now quite comfortable using autosizing masks in IB but there are two autosizing setting that I am not clear how they are intended to differ:
Autosizing with only uppper anchor http://img.ioscake.com/xcode/autosize-mask-1.png
Some context. The UIView subclass that uses these settings is a child subview. Setting 1 is giving me the behavior I want – subview expands/contracts with its parent view – while setting 2 is slightly different in a non-obvious way.
What is the intended layout difference between these two settings?
2 Solutions Collect From Internet About “Xcode Interface Builder. How Do These Autosizing Mask Settings Differ?”
The view will resize vertically so that both the distance from the top of the superview and the distance from the bottom of the superview are preserved. Basically, the view will grow and shrink in tandem with the superview; if the superview gets taller by 30 pixels, so will this view.
The view will resize vertically so that the distance from the top of the superview is preserved, and the proportional height of the view is preserved. Basically, the view will grow proportionally with the the superview; if the superview gets taller by 10%, this view will also get taller by 10%.
Note how these differ in practice. Assume the superview is 100px tall, and the subview is 60px tall, with a 20px buffer on the top and bottom. Now let’s resize the superview to 150px tall.
- Setting 1: The subview grows to preserve the 20px margins, becoming 110px tall.
- Setting 2: The subview grows by 50% (60px -> 90px). The top margin is still 20px, but the bottom margin is now 40px.
In general, you usually want the behavior in Setting 1. You might use Setting 2 if you had a master/detail view split top/bottom, and you wanted both sections to grow proportionally with the superview. In that case, you would give both views flexible height, fixing the top margin of the top view and the bottom margin of the bottom view.
BJ’s answer is really awesome. But I think his example is incorrect.
Assume the superview is 100px tall, and the subview is 60px tall, with
a 20px buffer on the top and bottom. Now let’s resize the superview to
So for Setting 2, the top margin is undoubtedly still 20px, but the subview and the bottom margin should both grow by (150 – 20) / (100 – 20) = 62.5%. The subview height becomes 97.5px, and the bottom margin is now 32.5px.
In other words, the proportion of the subview height to the bottom margin should be preserved in this case.
- iOS splash Screen Animation
- UICollectionView like iOS Home Screen
- Is it possible to use NSArray, NSDictionary, and NSNumber “literals” in Xcode 4.3? (LLVM 4.0)
- How to handle UserNotifications Actions in iOS 10
- Strong reference to a weak references inside blocks
- File sharing / send file in another app (“open in” in iOS)
- Enabling Bitcode for iOS 9 increases IPA size 3x, is this the size on the app store?
- Google Places Api iOS Daily Limit for Unauthenticated Use Exceeded error
- One C# game to rule them all(iOS, Android, WP7, W7, Mac OS X and XBOX)
- Replicating the style of the iOS Mail App's Compose Function
- Ambiguous use of subscript
- Swift – Custom System Keyboard Within my app only
- How to fetch the phone number for the imessage extension created application
- How to check does method systemFontOfSize(fontSize: weight:) exist in iOS
- Auto-renewable subscription in ios7