Analogically, after you leave the LANDSCAPE controller, whatever controller you load, you should force again autorotation for IOS 5, but now you will use UIDeviceOrientationPortrait, as you go to a PORTRAIT controller:- (void)viewDidLoad{ [super viewDidLoad]; if ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0) [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO]; }现在最后一件事(有点奇怪) - 您必须根据 IOS 更改从控制器切换到另一个控制器的方式:创建一个 NSObject 类Schalter"(德语中的Switch").Make an NSObject class "Schalter" ("Switch" from German).在 Schalter.h 中说:In Schalter.h say:#import <Foundation/Foundation.h>@interface Schalter : NSObject+ (void)loadController:(UIViewController*)VControllerToLoad andRelease:(UIViewController*)VControllerToRelease;@end在 Schalter.m 中说:In Schalter.m say:#import "Schalter.h"#import "AppDelegate.h"@implementation Schalter+ (void)loadController:(UIViewController*)VControllerToLoad andRelease:(UIViewController*)VControllerToRelease{ //adjust the frame of the new controller CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame]; CGRect windowFrame = [[UIScreen mainScreen] bounds]; CGRect firstViewFrame = CGRectMake(statusBarFrame.origin.x, statusBarFrame.size.height, windowFrame.size.width, windowFrame.size.height - statusBarFrame.size.height); VControllerToLoad.view.frame = firstViewFrame; //check version and go if (IOS_OLDER_THAN_6) [((AppDelegate*)[UIApplication sharedApplication].delegate).window addSubview:VControllerToLoad.view]; else [((AppDelegate*)[UIApplication sharedApplication].delegate).window setRootViewController:VControllerToLoad]; //kill the previous view controller [VControllerToRelease.view removeFromSuperview];}@end现在,这就是您使用 Schalter 的方式(假设您从仓库控制器转到产品控制器):#import "Warehouse.h"#import "Products.h"@implementation WarehouseProducts *instance_to_products;- (void)goToProducts{ instance_to_products = [[Products alloc] init]; [Schalter loadController:instance_to_products andRelease:self];}bla-bla-bla your methods@end当然你必须释放instance_to_products对象:- (void)dealloc{ [instance_to_products release]; [super dealloc];}嗯,就是这样.不要犹豫,投反对票,我不在乎.这是为那些正在寻找解决方案的人准备的,而不是为了声誉.干杯!萨瓦·马扎雷. 这篇关于IOS 6 强制设备方向为横向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-15 14:52