[英]Orientation changes when pop back to the initial viewcontroller using UINavigationController iOS 6
I have a presented a navigation controller, in which the root view controller i,e. 我有一个导航控制器,其中根视图控制器i,e。 VC1 is supported for both landscape & portrait orientations.
横向和纵向方向均支持VC1。 When i push another view controller in landscape the i,e.
当我在横向推动另一个视图控制器i时,e。 VC2 which supports only portrait mode, come back to the VC1, the view will be turned to portrait.
VC2只支持纵向模式,回到VC1,视图将变为纵向。 But i am still in the landscape mode.
但我仍然处于横向模式。 Please help me to solve this on iOS 6 issue.
请帮我解决iOS 6问题。
Please check the below code. 请检查以下代码。
MyViewController1 *theController =[[MyViewController1 alloc] init];
UINavigationController *navCntlr = [[UINavigationController alloc] initWithRootViewController:theController];
[self.navigationController presentViewController:navCntlr animated:YES completion:nil]; [theController release];
[navCntlr release];
in MyViewController1 在MyViewController1中
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
in VC2/MyViewController2 i have added the below code. 在VC2 / MyViewController2中,我添加了以下代码。
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
i have subclassed the root navigation bar as well. 我也已经将根导航栏子类化了。
Actually this was identified as a bug in IOS6 happens with ImageViewController which only supports Portrait orientation ... so i spent lot of time and found a way around the same.... 实际上这被认为是IOS6中的一个错误发生在ImageViewController上,它只支持Portrait方向...所以我花了很多时间并找到了相同的方法....
hope this helps so first things first... 希望这有助于首先......
add a property in your AppDelegate.h 在AppDelegate.h中添加一个属性
@property BOOL model;
then in AppDelegate.m 然后在AppDelegate.m中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.model=NO;
return YES;
}
also add this method in AppDelegate.m 也在AppDelegate.m中添加此方法
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(!self.model)
return UIInterfaceOrientationMaskLandscape; //or needed orientation
else
return UIInterfaceOrientationMaskAllButUpsideDown;
}
then in your view controller before presenting the VC2 然后在你的视图控制器中呈现VC2之前
implement this code... 实现此代码......
AppDelegate *appdelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
appdelegate.model=YES;
and then you just change the value in the viewWillDisappear of VC2 然后你只需更改VC2的viewWillDisappear中的值
AppDelegate *appdelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
appdelegate.model=NO;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.