UIScrollView constraints based off storyboard - ios

I'm trying to have a pictures be part of a scroll view in a gallery. I added 4 constraints: aspectRatio, Center Vertically, and a -12 margin spacing to the nearest neighbor (the view) on the left and right side.
For some reason when the UIView in the Storyboard is a 4-inch iPhone the iPhone 5 and 5s are aligned and the 6 and 6s are messed up. If I change the UIView size to an 4.7-inch iPhone (leaving the constraints alone), the 5 and 5s are misaligned and the 6 and 6s are fine. I think the initial size of the scroll view is initialized when the view first builds itself which is initially in the size of your storyboard. So I tried printing out the frame to debug. When the iPhone in the storyboard is 4.7 inch the frame prints out to (-1,83,377,500) which works perfectly. When the Storyboard is a 4 inch the frame prints out (-1,70,322,427)
I tired using scrollView.layoutIfNeeded, which helps and prints (-9,72.5,393,522) but doesn't get the frame the same as if the Storyboard was set to the 4.7 iPhone.
Edit: Screenshots

Ah I solved it. It seems like I was calling scrollView.frame too early. Using it in viewDidLoad is too early it can't be used until viewDidLayoutSubviews(). Massive headache gone!

Related

Autolayout with subview screen issue different devices

I have designed simple one page design for universal application. so I had faced issue while checking the 4 inch devices its working fine. other than 5.5 to above devices its not looking good.
View(MAINVIEW)
ScrollView
View
Label
..
..
above I have mentioned the structure of the page.below I have mentioned screen shots.
above Screen shots image I have designed. with all constraints.
after that I have checked the preview of the page design.
Iphone 4-inch its showing fine. but Iphone 5.5 its showing in bottom not filled whole page view.
It looks like then you have set the height constraint for ScrollView or view. If you did this then remove that height constant and set the bottom constraint which should have 0 constant value to its superview.

How to Configure AutoLayout for UIView

I have a UIView in my iOS app that holds a graph. I have fully constrained the UIView in Interface Builder but yet when I view the page on my iPhone 6 the graph is a nice large size but yet when viewed on an iPhone 4s, the view appears much shorter to the point where it's uncomfortable to look at.
The constraints are as follows:
As viewed on an iPhone 4s:
As viewed on an iPhone 6:
How can I adjust the constraints so that the iPhone 4s UIView has similar proportions to that of the iPhone 6?
There might be some conflict in the constraints in 4S.
For this UIView, if the superview is fixed in terms of size, then only 2 of the following constraints need to be set.
align top to superview
align bottom to superview
height equals 150
Or if the superview is not fixed in size, then the superview constraints might have conflict with the tableview down below. try to set the tableview height using percentage, not the fix number?

ImageView width more than cell width in UITableView Cell - XCode 6

I am developing an application in XCode 6 for iOS 8. I am not using auto-layout. I am trying to put an ImageView in a UITableView cell. When i run the app on iPhone 6/6 Plus:
The size of the imageView becomes double than my cell size if i check all the auto-resizing options.
The size of the imageView becomes lesser in width if i uncheck all resizing options except for the left one.
Is this some bug in XCode? Because I think, if i check all the auto-resizing options, and use scale to fill for the imageView, it should scale up and down accordingly, rather than going out of bounds of the view and cell.
All help is appreciated.
I ended up finding out that it all depends upon the splash screens you have added. AutoResizing proves troublesome on iPhone 6 and 6+ if you have splash screens for them.
But if you remove those splash screens and only keep a splash screen for iPhone 5, then your app will properly scale up and down, hence the bug will be resolved.

Why does my View frame size change when using Autosizing in Portrait mode?

I'm trying to understand how Autosizing works. After reading some posts like How to Automatically Resize a UIView When The Orientation Changes, iOS 4 iPhone Rotation, View Resizing and Layout Handling, Understanding UIView autoresizing, ...
I think that Autosizing only works when there is orientation changes so that the View can be displayed properly, but it doesn't. It does resize my View frame size either when I'm only in Portrait mode. Why is that ?
I cannot fully tell from your screen shot, but I assume that in your storyboard the view is in the 4 inch dimensions. Then you are using the 3.5 inch simulator. Since you have made your sizing constraints say in essence...
"Keep my view this far from the top and this far from the bottom, and resize its height to force this"... Your view will shrink that half inch to make sure it matches your constraints.
Try running it in the 4 inch simulator and see if that works.

Xcode UIToolbar Autoresize

I have an iPhone application that runs perfectly on the iPhone 4s but when run on an iPhone 5 some parts of the screen doesn't autoresize. The thing that isn't resizing is the UIToolbar. My application always runs in Landscape mode, so the toolbar is at the bottom of the screen and these are the dimensions of the toolbar:
X: 0 Y: 256
Width: 480 Height: 44
I've tried adjusting the auto-resizing tool to almost every combination and nothing works. I can get the toolbar to spread across the screen, but the 3 buttons stay the same size. Each button is of width = 148. Is there an easier way to have the entire application just automatically resize correctly? For some reason my iPhone app worked great on the iPad when you used the "x2" resize view. Thoughts?
so the OP uses stock items and they don't resize then!
I would add flexible spacer items in between each button -- they resize
To solve my problem I just used IBOutlets that connected to each barbutton and if the screen size was for the iPhone 5, the width would adjust accordingly for each screen, if regular screen (iPhone 4s and below); then stay the same. Not a very efficient way but it worked for me.
Take a look at the images and select the autosizing red lines, if you select the bottom line it will keep on the bottom always, and if you select top and bottom it will stay at the same place. So verify your UIToolBar autosizing properties.
EDIT
EDIT2
Check out this answer How to detect iPhone 5 if you can't autosize, one quick solution that occurs mi if to change the frame in the code. Check if the device is a iPhone 5 or 4S to give a specific frame so you can adjut the width.

Resources