How to get iPad screen size in different orientations? - ios

I am writing my first iPad application. One of the very first problems i ran into is the screen size in different orientations.
When i try using these two:
view.frame
or
view.bounds
I get the screen resolutions for the portrait mode. Note that i need both the large and mini iPad screen size. I have also tried using mainScreen but i get the same results as the above codes.

Here you go
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
CGFloat width = CGRectGetWidth(self.view.bounds);
}
Please mark as answer/vote if this helped you.

Related

Getting Wrong Screen Sizes in iPhone 6/6+

I am getting wrong screen size in iPhone 6 and 6+ by using
[UIScreen mainScreen].nativeBounds
and
[UIScreen mainScreen].bounds
In both case , i am getting wrong screen size.
So, I have added launch screen for iPhone 6 and iPhone 6+ then I get correct size of screen in iPhone 6 and iPhone 6+.
But another problem is that My App UI displaying wrong. All Screens of app left right padding. See below image :
If I remove launch screen for iPhone 6 and 6+ then App UI is displaying right as displaying before like below image :
In above image, no right padding.
I have also check by adding launch screen but that also getting wrong screen sizes.
Note : I have used AutoResize in app and It is working good in whole app.
I have also do so much googling to find out actual problem but unfortunately can't get it. Thanks so much in advance If anyone help to sort out that problem.
Sorry, did you check Settings -> Display and brightness -> View (Standart)?
One of the possible patch to identify your screen type is by getting the scale of your screen. You can use the following code : [UIScreen mainScreen].scale;
This will not let you know the exact screen size but will allow you to know what is the scaling. This method might be helpful where you need not to code individually for different screens and majorly do not want to convert your entire code to autolayout.
To know the scaling factor of different screens refer to following link : http://www.paintcodeapp.com/news/iphone-6-screens-demystified

iPad app displaying iPhone screen size

I am working on an app and it has 3 storyboards - iPad, iPhone and iPhone 4. 3 different users (myself included) have had the experience where on their iPad - the splash screen that loads is small and in the top-left corner...leaving much white space to the right and bottom.
It is as if it is loading the iPhone size splash.
I have no launch screen file selected in the general tab of the project. I have also noticed that after restarting my iPad, it does seem to load the proper screen size. Any ideas as to what is going on?
Use this line of code for screen size.
CGRect screen_size = [[UIScreen mainScreen]bounds];

Adapting UIButton sizes to iphone 6 and 6 plus

I am a little lost here.
Consider in a landscape mode I have 3 UIButtons which are of equal widths aligned next to each other with a gap and the occupy the entire space of the screen. These buttons were added programatically with fixed button sizes.
All looks fine and nice in a iPhone4s screen. Now comes the iphone6+. The way I am determining the button sizes is
buttonWidth = 21.f * [[UIScreen mainScreen] scale];
And then the button seems to fit good for the iPhone 6+ screen and covers the full area.
Will it work for iPhone 6 as well ?
Is this the right approach? How do i determine different sizes for the buttons for different screen sizes? Yes, I know adaptive layout, but we still have to specify the button sizes, dont we?
Help would be great appreciated.

How to detect if ios8 custom keyboard extension is running in not iphone 6 optimized app?

In the app that not optimized for iphone 6 in standard display mode keyboard and status bar shows zoomed. This causes my manually layouted custom keyboard extension to show streched. How can I detect this zooming to fix layout?
Use self.view.frame.size.width It returns 320 for zoomed mode & 414 for regular mode on my 6+ (hopefully on 6 also) in - (void)updateViewConstraints
Eventually you will not need to do this as whatsapp and other apps get updated (I believe whatsapp just did) but how I get around it temporarily is by getting the size of the view where I am drawing my keyboard view.
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
The iPhone 6 and 6+ will tell you that your screen width 320 for portrait and 568 landscape like an iPhone 5. You can then use the same drawing you do for the iPhone 5.
When the app is optimized for the iPhone 6 and 6+ you will get their real measurements.
Something I don't get is why people are downvoting my answer when it is the right one. We had to specifically deal with this problem. When the app where your extension runs is not optimized for iPhone 6 the dimensions are the same as the previous iPhone and the app is scaled up to full screen. Just run in an iPhone 6 an old app that was never updated and see it for yourself.

iOS Development in Preperation for Larger Screen

In preparation for a possibly bigger screen in the iPhone 6, we can obviously programmatically base layouts around screen bound size, but how do we ensure the custom xib files are formatted? For example, I have a custom UITableViewCell that is set to 320x145 in storyboard. Can I somehow prepare this for a different sized screen?
Have you looked at the new Xcode6 beta? As far as I can see, we are able to create freeform views there in storyboards:
Looks like this (+ Auto Layout) allows us to be prepared for flexible interface types.
If you truly need to prepare for something that is rumored, I would suggest the same methods that everyone used when preparing for the iPhone 5:
Download and install latest version of Xcode.
Set a 6-inch launch image for your app. This is how you get new screen height (without it, you will get 1136 px with black margins on top and bottom).
Test your app, and hopefully do nothing else, since everything should work magically if you had set auto resizing masks properly.
If you didn't, adjust your view layouts with proper auto resizing masks or look into Auto Layout if you only want to support iOS 6 going forward.
If there is something you have to do for the larger screen specifically, then it looks like you have to check height of [[UIScreen mainScreen] bounds] (or applicationFrame, but then you need to consider status bar height if it's present) as there seems to be no specific API for that.
Example:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == new screen height) {
// code for 6-inch screen
} else if (screenBounds.size.height == 1136) {
// code for 4-inch screen
}
else {
// code for 3.5-inch screen
}
The absolute best thing that you can do this time around (not just doing a bunch of if's everywhere) is to use Size Classes in your Storyboards.
Whats new in Xcode:
Size classes
Size classes for iOS 8 enable designing a single universal storyboard with customized layouts for both iPhone and iPad. With size classes you can define common views and constraints once, and then add variations for each supported form factor. iOS Simulator and asset catalogs fully support size classes as well.

Resources