iOS6 Interface Orientation


In iOS6 for interface orientation shouldAutorotateToInterfaceOrientation: method is deprecated.
If you want to make only one controller to orient in all directions but want to restrict a single controller to a specific direction like Portrait then follow:
1. Subclass a UINavigationController and inherit it
2. Override few orientation methods in ViewController in which you want or restrict the orientation support.


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

-(BOOL)shouldAutorotate


-(NSUInteger)supportedInterfaceOrientations



If you want to restrict a ViewController to rotate only in Portrait mode then add code:

#pragma Orientation (override methods)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}



If you want to allow all orientations on a ViewController then add below code:


#pragma Orientation (override methods)
-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}



You can download sample code : Code Here





I followed below link for help:

Comments

Popular posts from this blog

UITableView - Add or Remove Rows Dynamically (Objective C & Swift Source codes)

payUmoney Payment Gateway Integration in iOS App (Objective C)

Check Internet Connectivity Using AFNetworking 2.0