我浏览了所有可以在这里找到的定向线程,并实现了其中的几个。每种方法都有90%的效果。以下是我正在制作的应用程序的一些背景信息。它有5个tabBarItems,显然每个都加载了不同的视图。其中的一些观点,我想做风景和肖像,但我只想成为肖像的一个观点。我有这个功能什么的。HomeView需要人像。它可以很好地加载肖像画,并且不会影响你如何旋转手机--然而,如果你切换到另一个支持景观的视图,将手机旋转成景观,然后触摸HomeView tabBarItem,它将加载景观,尽管它被设置为只加载纵向。下面是HomeView控制器中当前的半工作代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[self orientationPortrait];
NSLog(@"[INFO] %@ loaded",self);
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:true];
[self orientationPortrait];
}
-(void)viewWillAppear:(BOOL)animated
{
[self orientationPortrait];
}
-(void)viewWillDisappear:(BOOL)animated
{
//NSLog(@"viewWillDisappear -- Start");
[self orientationPortrait];
}
-(void) orientationPortrait {
TechBookAppDelegate *appDelegate = (TechBookAppDelegate *) [[UIApplication sharedApplication] delegate];
appDelegate.screenIsPortraitOnly = YES;
}
-(void) orientationBoth{
TechBookAppDelegate *appDelegate = (TechBookAppDelegate *) [[UIApplication sharedApplication] delegate];
appDelegate.screenIsPortraitOnly = FALSE;
}In AppDelegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if(self.screenIsPortraitOnly == NO){
return UIInterfaceOrientationMaskAll;
} else {
return UIInterfaceOrientationMaskPortrait | !UIInterfaceOrientationMaskAll;
}
}另一个tabBarItems ViewControllers只有在需要的地方调用orientationBoth方法,并在viewWillDisappear上调用orientationPortrait,因为我希望当视图移回HomeView时,它将帮助将视图设置为纵向,但它似乎不起作用。
请告诉我谢谢。
发布于 2014-04-11 17:32:51
我已经解决了这个问题,通过重新组织布局的HomeViewController方向改变.
https://stackoverflow.com/questions/22947007
复制相似问题