I recently upgraded to Xcode 4. Previously in Xcode 3 to set the allowed device orientations you had to edit the shouldAutorotateToInterfaceOrientation:
method in the application delegate. But now in Xcode 4 I see there is an option in Targets -> Summary where you can select different orientations.
Which alternative will rule over the other?
Cheers,
Peter
The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.
func application(UIApplication, supportedInterfaceOrientationsFor: UIWindow?) -> UIInterfaceOrientationMask. Asks the delegate for the interface orientations to use for the view controllers in the specified window. enum UIInterfaceOrientation. Constants that specify the orientation of the app's user interface.
You can change the orientation to the one you like by calling the function changeOrientation . You can also reverse an orientation change after it's done, using the . onReceive .
SwiftUI doesn't have a built-in way to detect the user rotating their device between portrait and landscape orientation, but we can make one using a custom modifier by responding to the UIDevice. orientationDidChangeNotification notification.
Your memory is slightly faulty; shouldAutorotateToInterfaceOrientation:
is in custom subclasses of UIViewController. So it allows each view controller to say which orientations it works in individually. So you can have an app that overwhelmingly works in portrait or landscape, but has a view view controllers that only work in portrait, for example — which is useful if you're incorporating off-the-shelf code.
The supported device orientations in targets -> summary go into your Info.plist, to provide metadata to the OS without it having to launch your app.
Ideally the two should agree, and I don't think either one overrides the other. The summary information should summarise all of your various view controllers, but I'd be surprised if you got anything other than the odd weird launch behaviour if you fill it in incorrectly.
The "target summary" is just short hand for the data in the Info.plist file and so this has been available before. Nothing new here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With