in ios 6 and ios 5 orientation methods are changed so that you might have to face some problems.I here provide the steps how to come out from that if you gave compatibilty from ios 5 to ios 7
->First in .plist give this value for the key UISupportedInterfaceOrientations
->First in .plist give this value for the key UISupportedInterfaceOrientations
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
-> In appDelegate apply this method:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAll;
}
->If you are using tabbar controller you have to make custom class for that.
CustomTabbarControllerViewController.h
@interface CustomTabbarControllerViewController : UITabBarController
@end
CustomTabbarControllerViewController.m
#import "CustomTabbarControllerViewController.h"
@interface CustomTabbarControllerViewController ()
@end
@implementation CustomTabbarControllerViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}
@end
the tabbar only support that orientation which is passed by its selected view controller
->If you are using navigation controller then make category of it
#import <UIKit/UIKit.h>
@interface UINavigationController (CustomUINaviagationController)
-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;
@end
#import "UINavigationController+CustomUINaviagationController.h"
@implementation UINavigationController (autorotation)
- (BOOL)shouldAutorotate {
return [self.topViewController shouldAutorotate];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return [self.topViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}
-(BOOL)disablesAutomaticKeyboardDismissal{
return NO;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[self.topViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
@end
In specific view controller apply this three methods
eg. in specific PropertyListViewController if you want to support portrait mode Only.
- (NSUInteger) supportedInterfaceOrientations
{
//Because your app is only landscape, your view controller for the view in your
// popover needs to support only landscape
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
No comments:
Post a Comment