Reputation: 1046
I am using in my app the view size to position a subview in code.
for example like this:
self.view.bounds.size.height
This subview has to be animated in and out of the view.
This has worked perfect on older devices, now I am trying to support iphone 5 and found out that I still get the height of the old devices. Everything except this animated view adapts perfect for iphone 5.
The only way to get the right size is if I change the size of the view in the xib, downside is that if I now run my app on iPhone 4 the view size is the 4inch view size.
What is the problem here? Or is this the way it is supposed to be and I have to create an extra xib file for iPhone 5?
Upvotes: 0
Views: 3793
Reputation: 1046
Alright so the answer is the following:
Like @mrwalker said make sure that the view automatically or programmatically resizes.
And be aware of the fact that the view is not yet resized in the viedDidLoad
method.
(This was my mistake)
If you need the resized views size do your stuff in viewWillAppear
there the view has already the right size.
thanks to @mrwalker and @AndyDev
Upvotes: 4
Reputation: 1409
I had a similar issue where I wasn't getting the correct height and using the Autolayout / autoresize didn't achieve the desired effect. I used the following code to determine the screen size and made the changes based on this.
if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 1136){
// iPhone 5 (1136px height)
} else {
// Not iPhone 5
}
}
Upvotes: 2
Reputation: 1903
You need to make sure your view is resized for the device it's running on. You could either:
I would only opt for (1) if you were intending on having a different layout (more / fewer buttons and such).
How you achieve (2) depends on whether you're using iOS 6's Auto Layout or the old autoresize model. Both methods can be controlled in the Utilities > Size Inspector in Xcode, or programatically.
If you have a single view & view controller, allowing the view to automatically resize to the parent window should be enough.
Upvotes: 3