Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4 Supported Device Orientations

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

like image 208
Peter Warbo Avatar asked May 17 '11 12:05

Peter Warbo


People also ask

What is a UIViewController?

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.

What is UIInterfaceOrientationMask?

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.

How do I change the orientation in SwiftUI?

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 .

How do I check orientation in SwiftUI?

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.


2 Answers

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.

like image 123
Tommy Avatar answered Sep 29 '22 11:09

Tommy


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.

like image 27
Eiko Avatar answered Sep 29 '22 09:09

Eiko