UIScrollView with Autolayout has different size in iOS 7 and iOS 8 - ios7

its simple. in Xcode 6 I add an scrollView to to the view which covers entire screen. add constraints like this:
then add a contentView in the scrollView:
then add a sample label:
the problem is here when I run it on device with iOS 8: the scrollview width is 320
but on device with iOS 7 width is 320+16 = 336
what am I doing wrong here? why scroll won't remain 320? this cause my custom collectionView flowLayout doesn't work well in iOS 7.

as I guessed it was because of using margins which was introduced in iOS 8. but I was wondering I don't use margins when layouting view in the IB. after hours struggling, today I saw I have used margins for the container of this View controller.
removing margins fixed the problem.
so if you want to support iOS 7 and below turn off constrain to margins when adding new constraints in the interface builder

Related

UIScrollview frame only updating correctly after scrolling

So I have created a UIScrollView as a subview of the view controller's view in Interface builder and set all auto layout constraints so that it resizes to fill its superview (Trailing, leading, bottom and top constrains set to zero with regards to its superview).
When I run the application, the scrollview does not initially update its frame to be the same size as its superview. the scrollview frame.size.width = 320 even though I am running it on iPhone 6 or iPhone 6 plus simulator.
As soon as I start scrolling, the scrollview frame gets updated to the correct value (same as its superview). why is this happening? shouldn't auto layout automatically resize the scrollview in relation to its superview?
The only way I managed to fix this is to add the following in viewDidLoad:
scrollView.frame = view.frame.
Any ideas why this is happening? It does not seem logical.
Many thanks
Ok, so after some experimentation, I figured it out.
I was checking the scrollview frame size in viewDidLoad and it was returning 320
However, it seems that auto layout will only do resizing AFTER viewDidLoad and will call viewDidLayoutSubviews() after it has finished resizing/repositioning...etc
Therefore, when I check the frame size inside viewDidLayoutSubviews, I get the right frame size 375 (for iPhone 6).
Thank you

Trouble auto sizing iPhone 5 storyboard to fit iPhone 6

I have developed an app using iPhone 5 storyboard. The storyboard contains many views and I haven't used any constraints on any of the views.
What I am trying to achieve is to make the iPhone 5 storyboard expand to fit on iPhone 6 and 6+ without the need for any constraints, is this possible?
I have read many answer on SO already which lead me to believe that it is possible to get it to work but have not yet succeeded.
I don't have any launch images set, and I ticked the 'Use Size Classes' box for the storyboard.
Why is the storyboard not auto sizing for the iPhone 6. It's driving me crazy.
I hope you can help me,
thanks.
Have you tried using the Autoresizing feature? Uncheck the size classes box and you will see the option to use autoresizing under the measurements section to resize your storyboard for the 6 and 6plus.
http://i.stack.imgur.com/qM4Vu.png
You wont have to use size constraints since you're only making it for the iPhones
Click the "Use Auto Layout" checkbox shown below
Also here is a link to the size of the Launch images you should be using for the 6 and 6 plus.
One way but not recommended. Don't add splash screen for 6 and 6+
If you don't add the splash screen for 6 and 6+ OS will automatically scale all your UI.
The default auto resizing masks, which you probably have, have a fixed top and left margin and a fixed height and width. This would give you all the views packed into the top left corner as you are seeing - the flexibility is all in the right and bottom margins.
You're seriously better off using constraints (even adding the default constraints will probably get you most of the way there) but if you insist on sticking with auto resizing, you need to set fixed left and right margins and flexible width. Height is a bit more difficult, you have to decide which elements will fill the extra space and have flexible height on those.
To ensure that your app supports multiple screen sizes (instead of just scaling up the smaller interface) you should add a launch image .xib file which is much easier than using lots of images.

Why does UITableViewCell always resize from 400 to 320 in storyboard

I'm working in XCode 6 for iOS 8 and portrait iPhone 5,6,6+. In Storyboard I set "Compact" width and "Regular" height, so my layout views' sizes are 400*800.
I created a UITableViewController with custom UITableViewCells, that are prototypes, also via storyboard. Config cell and set constraints work okay, no yellow warnings in storyboard.
Then I reload XCode and all my labels, images, and buttons inside the cell are shifted -80 by "y" and have warnings, however the content view for cell still has a width of 400.
It's looks like this:
(http://prntscr.com/5d8snp)
This behavior is observed for all my UITableViews. Can you suggest something? In code I also didn't do anything, it's all in storyboard and UITableView.

How can I support a split view in landscape on the iPhone 6 or 5s?

In my app there's a lot of wasted space in landscape on the iPhone 6, and to a lesser extent even on 4" screens. I'm already using iOS 8's UISplitViewController changes to support the two-pane view in landscape on the iPhone 6 Plus, but it'd be useful to see both panes on some smaller devices as well.
Conveniently Apple had a WWDC 2014 session, "Building Adaptive Apps with UIKit" which included details on exactly how to do this. You can download the sample code here, but in short: they put the UISplitViewController inside of a UIViewController subclass. The subclass uses setOverrideTraitCollection:forChildViewController: to force [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular] on the split view when it considers the width wide enough. At the time the sample code worked well, and still does on most devices.
However after attempting to use this code in my own app, I discovered it fails horribly on the iPhone 6 Plus. You can see this yourself if you download the sample code and make two changes:
Add a storyboard, add an empty view controller to that, and set it as the "Launch Screen File". This is necessary to run the app at its native resolution on the 6 Plus.
In AAPLTraitOverrideViewController.m, change line 21 to size.width > 500.0, or anything greater than 414. This is necessary to ensure the split view only shows a single view in portrait on the 6 Plus.
Now you can run the app in the simulator. To see the problem, just do this:
Rotate the device to landscape (command-right arrow)
Rotate it immediately back to portrait (command-left arrow)
You can already see that something's not right. All of the table cells should have an arrow on the right side in portrait, but they don't. They're behaving like they're still in a split view. If you tap one of those rows, it gets worse—the detail view slides up from the bottom, and the navigation bar is gone.
I think there must be a bug in iOS 8 here that's causing the problem. But since this code was shared before the iPhone 6 Plus was announced, it also seems possible that it just needs some adjustments to make it compatible with that device. So far the only solution I've found is to change line 21 to something like if (size.width > 500.0 && size.width < 736.0) but I don't want to use code that could break again the next time Apple introduces a new screen size. Is there a better way to handle this?
Seems like you'll always want to make the horizontal size class regular (UIUserInterfaceSizeClassRegular). To do this, override traitCollectionDidChange:. In this method, if the vertical size class is compact (suggesting it's likely in landscape), override the trait collection so that the horizontal size class is regular.
UITraitCollection *compactHeight = [UITraitCollection traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassCompact];
if ([self.traitCollection containsTraitsInCollection:compactHeight]) {
UITraitCollection *regularWidth = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
self.forcedTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:#[self.traitCollection, regularWidth]];
[self setOverrideTraitCollection:self.forcedTraitCollection forChildViewController:_viewController];
} else {
[self setOverrideTraitCollection:nil forChildViewController:_viewController];
}
However, if you'll want more specific behavior, you'll have to rely on canvas size for app-specific behavior.

How to prevent UISegmentedControl from scaling segment images on iOS 7

I have an UISegmentedControl with 100x42 bounds. I've set up three segments with 26x26 images and 4x42 divider images. The three segment images should fit in the segments, but they are scaled and for the worse they seem to fit vertically and are only scaled down horizontally, thus loosing proportions.
This problem appeared after i changed to Xcode 5 and iOS 7 SDK. Before that the segment images were displayed with correct proportions and in original size.
I'm not using interface builder. I've tried to set the segment sizes manually and setting the segmented control's contentMode to UIViewContentModeScaleAspectFill without help.
Is there any way to force the UISegmentedControl to simply render the images as they are?
You may set auto layout constraints to correctly define UISegmentedControl frame. Like this
I know this is a late answer but I have the same issue testing an app for IOS 7.1.
If you set the image in the code it's working properly. Example:
- (void)viewDidLoad {
[super viewDidLoad];
[_segmentedControl setImage:[UIImage imageNamed:#"779-users-toolbar"] forSegmentAtIndex:0];
}
In my project I have the normal image, and the #2x & #3x versions of the image.
I tested the code in 7.1, xcode 6.1.
When I run it in 8.1 the image set via IB works properly as well, so this may be a bug in 7.1 that has been fixed in 8.