Conditionally allow rotation on iOS 8 - ios8

On iOS 8, apps like Weather and Clock rotate on the iPhone 6 Plus but not on the smaller-screened iPhone 5S. I can override supportedInterfaceOrientations but is there a better way to detect the 6 Plus screen other than specific checks like screen bounds or device model?
I looked into size classes, but couldn’t find a way to detect if a device returns UIUserInterfaceSizeClassRegular on Landscape orientation before the device is actually rotated.

I'm supporting iOS 7 too so I've stuck with checking the screen scale > 2 but if you are on iOS 8 you can use the trait collection. The 6+ in landscape is "regular" width while other iPhones are "compact" width.
See the Apple What's New doc for more info

Related

How to prevent Storyboard from resizing (stretching) a UIImage centered on a UIView?

I have a Universal iOS app and am trying to move from old-style launch images to a simple centered image on a storyboard Launch screen, so I have a single storyboard for all devices. My image (640x1136, iPhone 5s size) needs to not be stretched when the app is run on devices with larger sizes than the image -- in other words, the background color of the UIView should appear surrounding the image on larger devices. For debugging purposes I changed the view background color to a gaudy Lime.
I defined 2 constraints on the UIImageView as directed in the SO post here according to the highest-upvoted answer (Suragch's) and in fact had to also follow the accepted answer's recommendation to add the additional UIView into which my UIImageView would be contained.
The "content mode" of the UIImageView is Center so seems there should be no stretching.
In the pic notice Xcode's Size Inspector settings for the UIImageView. The UIView has iPhone 7-sized dims (750x1334) and so because that iPhone is taller than my image the UIImageView is positioned so that its X is 55, Y is 99. The width and height are same as the image itself (640x1136).
When I run in Simulator an iPhone 7 seems it should look like exactly as what Xcode's Interface Builder shows (Lime color appearing all around the image, but instead, for any device larger than an iPhone 5s or SE it looks like the pic I've attached (an iPad Air, FYI). You can tell the image must be stretched quite a bit vertically because the image is only 1136 tall.
I've attached screenshots for the iPhone 7 (simulator) iPad Air and iPad Pro. Notice the horizontal strips of lime color appear on the right and left edges of the iPad Air. And notice that when it comes to the iPad Pro the lime background color begins to be shown above the image. It's as if on the smaller devices the system is stretching the UIImageView, but as device screen size increases this eventually stops, until for the largest (the Pro) you can actually see the background all around. It seems that for all device sizes listed in the Apple docs that are taller than iPhone 5s or SE, there should be no stretching/distortion. This is what I'm trying to accomplish.
Interface Builder size settings
iPhone 7 (simulator) screenshot
iPad Air (device) screenshot
iPad Pro (device) screenshot
I was able to get this to work finally, by completely eliminating the constraints and only using the autoresizing settings found when you choose the Size Inspector. The UIImageView now retains its specified size and is not stretched.
Try adding a width/height constraint to your ImageView:
This is done by first selecting your ImageView and then selecting this |-☐-| icon (located at the bottom right of the Storyboard window, next to the option where you can change the type of device)
Okay, I think I've figured out the problem. Your image is sized too large. You say you want it to be the size of an iPhone 5, and it's display size is 1136x640 pixels. This is not the same as the width/height in Xcode. To get this, change the device to iPhone 5 (or similar) and get the size. For instance, the size of the View for an iPhone 8 is 667x375. Then your image won't be cut off.

Get iPhone 5s app to scale to iPhone 6 resolution in Xcode Storyboard

I want my iPhone 5s app to simply upscale for the iPhone 6. I have no Launch Images in the project, but I do have the interface builder location declared in the plist to get rid of the black bars. How can I get the app to just upscale, right now it shows white space in Storyboard.
Looking at your question it looks like you are using absolute frame values for positioning, by setting frame.size.{width, height} and frame.origin.{x,y}.
You have two options.
set those values programatically. It's not recommended at all but might be easier to setup. Detect what is the screen's size with [[[UIScreen mainScreen] bounds] size] (check for the height property) or detect the device's version (eg Determine device (iPhone, iPod Touch) with iPhone SDK).
a less slippery road is to transform your project an start using AutoLayout. There's a learning curve but it guarantees that your project will be fitting well any screen. Start here: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html

Xcode 6 beta 4 Size Classes not good size

I want to use the new tech of apple, the Size Classes, but i don't understand why when i select the iphone size, my view have a width of 400p while my iphone have a width of 320p.
Anybody have an idéa ?
Thank
You should watch the WWDC video on developing adaptive apps. Basically, an iphone in portrait has Regular height and compact width size class. This has nothing to do with the real pixel dimension, since Apple might introduce a new phone that's 350pt wide, but still has the same size classes, so your code would work.
Watch the WWDC session video, and use size-classes together with auto-layout to make your apps.

Xcode 6 – Unified storyboard & Size Classes

How does auto-layout work to create interfaces in Xcode 6 beta? What are different size classes & how do they work? How to use the "Resizable Unified Storyboard" to create universal iOS app?
I think you are talking about "Size Classes" introduced in XCode6.
A size class is a new technology used by iOS to allow you to custom your app for a given device class, based on its orientation and screen size.
There are presently four size classes.
At any time your device is going to have a horizontal size class and a vertical size class.
You don't need to worry about device size. Whether it is iPhone 4s, 5 or mighty iPhone 6. UI would be handled automatically for you...
For more info read this article.
See this WWDC Video for more clarity..Building Adaptive Apps with UIKit
With that new feature only aspect ratios are defined. Click at the button "blue" area and you will see the description for the aspect:
wAny hRegular -> For all regular height layouts (e.g. iPhones in portrait, and iPads in portrait or landscape)

Scale images and buttons of layout in Xcode

How can I stretch the height of buttons and images in Xcode 4.6.3 in Storyboard?
I have a simple navigation with some images and a few navigations buttons as per the images below. In the first image its displayed on iPhone 4 and on image 2 its on iPhone 5. As you can see the buttons are now looking a bit lost on the bigger display.
Can I stretch the buttons' height for the iPhone 5 in Storyboard? I have seen examples of using Autolayout but they all seem to do with orientation (switching from portrait to landscape).
Can what I need to do be done with Struts and Springs perhaps? I am unable to test at the moment as I only have access to Xcode once a week. Just want to have as much information for the next time I get to work on project.
iPhone 4 display
iPhone 5 display
that's actually really easy to awnser! Just use autosizing. Here is what you need to do:
Xcode 4.5: How do I fix my text views so they display properly in portrait and landscape mode on an iPad?
Just play around with the inner cross and see what happens. You need to set the autosizing for every button if you want to resize them all.
Have a good one,
Noah

Resources