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

Parameters
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 :
        UIInterfaceOrientationMaskPortrait;
}

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

End of UIApplication supportedInterfaceOrientationsForWindow example article.

UIApplication setStatusBarStyle animated example in Objective C (iOS).

UIApplication setStatusBarStyle animated


Sets the style of the status bar, optionally animating the transition to the new style.

- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated

Parameters
statusBarStyle
A constant that specifies a style for the status bar. See the descriptions of the constants in UIStatusBarStyle for details.
animated
YES if the transition to the new style should be animated; otherwise NO .

Discussion of [UIApplication setStatusBarStyle animated]
The animation slides the status bar out toward the top of the interface.


UIApplication setStatusBarStyle animated example.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent
                                            animated:YES];

Example of [UIApplication setStatusBarStyle animated].
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
}

UIApplication setStatusBarStyle animated example.
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // don't forget to set navigationBar.translucent to YES
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
    [UINavigationBar setAnimationDuration:3.0];

    [UINavigationBar beginAnimations:@"" context:nil];
    [[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:NO];
    if ([UIApplication sharedApplication].isStatusBarHidden)
        [self.navigationController.navigationBar setAlpha:0.0];
    else [self.navigationController.navigationBar setAlpha:1.0];
    [UINavigationBar commitAnimations];
}

End of UIApplication setStatusBarStyle animated example article.

UIApplication setStatusBarStyle example in Objective C (iOS).

UIApplication setStatusBarStyle


Sets the style of the status bar, optionally animating the transition to the new style.

- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated

Parameters
statusBarStyle
A constant that specifies a style for the status bar. See the descriptions of the constants in UIStatusBarStyle for details.
animated
YES if the transition to the new style should be animated; otherwise NO .

Discussion of [UIApplication setStatusBarStyle]
The animation slides the status bar out toward the top of the interface.


UIApplication setStatusBarStyle example.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent
                                            animated:YES];

Example of [UIApplication setStatusBarStyle].
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
}

UIApplication setStatusBarStyle example.
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // don't forget to set navigationBar.translucent to YES
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
    [UINavigationBar setAnimationDuration:3.0];

    [UINavigationBar beginAnimations:@"" context:nil];
    [[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:NO];
    if ([UIApplication sharedApplication].isStatusBarHidden)
        [self.navigationController.navigationBar setAlpha:0.0];
    else [self.navigationController.navigationBar setAlpha:1.0];
    [UINavigationBar commitAnimations];
}

End of UIApplication setStatusBarStyle example article.

UIApplication setStatusBarOrientation animated example in Objective C (iOS).

UIApplication setStatusBarOrientation animated


Sets the application's status bar to the specified orientation, optionally animating the transition.

- (void)setStatusBarOrientation:(UIInterfaceOrientation)interfaceOrientation animated:(BOOL)animated

Parameters
interfaceOrientation
A specific orientation of the status bar. See UIInterfaceOrientation for details. The default value is UIInterfaceOrientationPortrait.
animated
YES if the transition to the new orientation should be animated; NO if it should be immediate, without animation.

Discussion of [UIApplication setStatusBarOrientation animated]
Calling this method changes the value of the statusBarOrientation property and rotates the status bar, animating the transition if animated is YES . If your application has rotatable window content, however, you should not arbitrarily set status-bar orientation using this method. The status-bar orientation set by this method does not change if the device changes orientation.


UIApplication setStatusBarOrientation animated example.
//will rotate status bar
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];


//will re-rotate view according to statusbar
UIViewController *c = [[UIViewController alloc]init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];

Example of [UIApplication setStatusBarOrientation animated].
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

UIApplication setStatusBarOrientation animated example.
-(void)rotateInterfaceToOrientation:(UIDeviceOrientation)orientation{

    CGRect bounds = [[ UIScreen mainScreen ] bounds ];
    CGAffineTransform t;
    CGFloat r = 0;
    switch ( orientation ) {
        case UIDeviceOrientationLandscapeRight:
            r = -(M_PI / 2);
            break;
        case UIDeviceOrientationLandscapeLeft:
            r  = M_PI / 2;
            break;
    }
    if( r != 0 ){
        CGSize sz = bounds.size;
        bounds.size.width = sz.height;
        bounds.size.height = sz.width;
    }
    t = CGAffineTransformMakeRotation( r );

    UIApplication *application = [ UIApplication sharedApplication ];

    [ UIView beginAnimations:@"InterfaceOrientation" context: nil ];
    [ UIView setAnimationDuration: [ application statusBarOrientationAnimationDuration ] ];
    self.view.transform = t;
    self.view.bounds = bounds;
    [ UIView commitAnimations ];

    [ application setStatusBarOrientation: orientation animated: YES ];    
}

End of UIApplication setStatusBarOrientation animated example article.

UIApplication setStatusBarOrientation example in Objective C (iOS).

UIApplication setStatusBarOrientation


Sets the application's status bar to the specified orientation, optionally animating the transition.

- (void)setStatusBarOrientation:(UIInterfaceOrientation)interfaceOrientation animated:(BOOL)animated

Parameters
interfaceOrientation
A specific orientation of the status bar. See UIInterfaceOrientation for details. The default value is UIInterfaceOrientationPortrait.
animated
YES if the transition to the new orientation should be animated; NO if it should be immediate, without animation.

Discussion of [UIApplication setStatusBarOrientation]
Calling this method changes the value of the statusBarOrientation property and rotates the status bar, animating the transition if animated is YES . If your application has rotatable window content, however, you should not arbitrarily set status-bar orientation using this method. The status-bar orientation set by this method does not change if the device changes orientation.


UIApplication setStatusBarOrientation example.
//will rotate status bar
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];


//will re-rotate view according to statusbar
UIViewController *c = [[UIViewController alloc]init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];

Example of [UIApplication setStatusBarOrientation].
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

UIApplication setStatusBarOrientation example.
-(void)rotateInterfaceToOrientation:(UIDeviceOrientation)orientation{

    CGRect bounds = [[ UIScreen mainScreen ] bounds ];
    CGAffineTransform t;
    CGFloat r = 0;
    switch ( orientation ) {
        case UIDeviceOrientationLandscapeRight:
            r = -(M_PI / 2);
            break;
        case UIDeviceOrientationLandscapeLeft:
            r  = M_PI / 2;
            break;
    }
    if( r != 0 ){
        CGSize sz = bounds.size;
        bounds.size.width = sz.height;
        bounds.size.height = sz.width;
    }
    t = CGAffineTransformMakeRotation( r );

    UIApplication *application = [ UIApplication sharedApplication ];

    [ UIView beginAnimations:@"InterfaceOrientation" context: nil ];
    [ UIView setAnimationDuration: [ application statusBarOrientationAnimationDuration ] ];
    self.view.transform = t;
    self.view.bounds = bounds;
    [ UIView commitAnimations ];

    [ application setStatusBarOrientation: orientation animated: YES ];    
}

End of UIApplication setStatusBarOrientation example article.

UIApplication setStatusBarHidden withAnimation example in Objective C (iOS).

UIApplication setStatusBarHidden withAnimation


Hides or shows the status bar, optionally animating the transition.

- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation

Parameters
hidden
YES to hide the status bar, NO to show the status bar.
animation
A constant that indicates whether there should be an animation and, if one is requested, whether it should fade the status bar in or out or whether it should slide the status bar in or out.

Discussion of [UIApplication setStatusBarHidden withAnimation]
See the descriptions of the constants of the UIStatusBarAnimation type for more information.


UIApplication setStatusBarHidden withAnimation example.
if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden: withAnimation:)])
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
else
    [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];

Example of [UIApplication setStatusBarHidden withAnimation].
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#if __IPHONE_OS_VERSION_MIN_REQUIRED > 30100
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:YES];
#else
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
#endif
#endif

UIApplication setStatusBarHidden withAnimation example.
if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden: withAnimation:)])
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}
else if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden: animated:)])
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
}
else if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden:)])
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
}

End of UIApplication setStatusBarHidden withAnimation example article.

UIApplication setStatusBarHidden example in Objective C (iOS).

UIApplication setStatusBarHidden

Hides or shows the status bar, optionally animating the transition.

- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation

Parameters of [UIApplication setStatusBarHidden]
hidden
YES to hide the status bar, NO to show the status bar.
animation
A constant that indicates whether there should be an animation and, if one is requested, whether it should fade the status bar in or out or whether it should slide the status bar in or out.

Discussion of [UIApplication setStatusBarHidden]
See the descriptions of the constants of the UIStatusBarAnimation type for more information.


UIApplication setStatusBarHidden example.
if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden: withAnimation:)])
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
else
    [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];

Example of [UIApplication setStatusBarHidden].
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#if __IPHONE_OS_VERSION_MIN_REQUIRED > 30100
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:YES];
#else
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
#endif
#endif

UIApplication setStatusBarHidden example.
if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden: withAnimation:)])
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}
else if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden: animated:)])
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
}
else if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden:)])
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
}

End of UIApplication setStatusBarHidden example article.