Wednesday, May 29, 2013

UIApplication supportedInterfaceOrientationsForWindow example in Objective C (iOS).

UIApplication supportedInterfaceOrientationsForWindow

Returns the default set of interface orientations to use for the view controllers in the specified window.

- (NSUInteger)supportedInterfaceOrientationsForWindow:(UIWindow *)window

The window whose default interface orientations you want to retrieve.

Return Value of [UIApplication supportedInterfaceOrientationsForWindow]
A bit mask specifying which orientations are supported. See “UIInterfaceOrientationMask” for valid bit-mask values. The value returned by this method must not be 0.

Discussion of [UIApplication supportedInterfaceOrientationsForWindow]
This method returns the default interface orientations for the app. These orientations are used only for view controllers that do not specify their own. If your app delegate implements the application:supportedInterfaceOrientationsForWindow: method, the system does not call this method.

The default implementation of this method returns the app’s default set of supported interface orientations, as defined in the UISupportedInterfaceOrientations key of the Info.plist file. If the file does not contain that key, this method returns all interface orientations for the iPad idiom and returns all interface orientations except the portrait upside-down orientation for the iPhone idiom.

UIApplication supportedInterfaceOrientationsForWindow example.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

return UIInterfaceOrientationLandscapeRight;


- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)w {

return (NSUInteger)[application supportedInterfaceOrientationsForWindow:w] | (1<

Example of [UIApplication supportedInterfaceOrientationsForWindow].
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {  

    return self.fullScreenVideoIsPlaying ?
        UIInterfaceOrientationMaskAllButUpsideDown :

UIApplication supportedInterfaceOrientationsForWindow example.
- (NSUInteger)application:(UIApplication*)application
    if(self.shouldRotate ) //shouldRotate is my flag
        self.shouldRotate = NO;
        return (UIInterfaceOrientationMaskAll);
    return (UIInterfaceOrientationMaskPortrait);

End of UIApplication supportedInterfaceOrientationsForWindow example article.