UIInterfaceOrientation更改无法在子视图中使用
我正在将UIInterfaceOrientation更改添加到应用程序。我的应用不是基于标签或导航的。我在其他上添加子视图。UIInterfaceOrientation更改无法在子视图中使用
我经历了为什么界面方向更改不起作用的文档? http://developer.apple.com/library/ios/#qa/qa1688/_index.html
我发现主窗口控制着界面方向的变化。
但是现在,由于我的应用不是基于标签或导航的,还有什么办法可以实现它吗?
P.S. :在我的应用程序中,只有启动屏幕对于界面方向更改正常工作,而不是添加的子视图。
请帮忙
在此先感谢。
使用以下方法调整子视图的大小。或使用autoresizingMask
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation == UIInterfaceOrientationPortrait){
viewInformationContainer.frame = CGRectMake(0, 61, 320, 403);// here you can change resize or subviews
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
viewInformationContainer.frame = CGRectMake(0, 0, 480, 227);//here you can change resize or subviews
}
}
希望,这将帮助你......
阅读上面贴的意见和你面对什么,我可以说的是,你已经添加子视图的层次结构问题。考虑以下情况
1)我添加一个视图控制器(VC),导航控制器,标签栏控制器直接到窗口..后续的视图将得到正确的任何方向更改通知。
2)我添加一个父视图控制器到窗口,然后添加一些其他视图控制器到我的父视图控制器的视图,在这种情况下,您将获得方向更改委托方法在父VC中正确调用,但而不是在后来的视图控制器的视图你已经添加到你的父VC
我曾经添加一个基本视图控制器到我的应用程序窗口,其中基本控制器有一个ScrollView,我后来添加我的四个视图控制器子视图滚动视图。
-
(无效)viewDidLoad中{
DNAppDelegate *appDelegate = (DNAppDelegate*)[UIApplication sharedApplication].delegate; CGRect viewCustormFrame = appDelegate.viewCustomTabBar.frame; viewCustormFrame.origin.y = self.view.frame.size.height-35; if(UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) { viewCustormFrame.size.width = self.view.frame.size.width; } else { viewCustormFrame.size.width = self.view.frame.size.width; } [self.view addSubview:appDelegate.viewCustomTabBar]; appDelegate.viewCustomTabBar.frame = viewCustormFrame; [srclViewMainContent addSubview:appDelegate.homeController.view]; [srclViewMainContent addSubview:appDelegate.newsListController.view]; [srclViewMainContent addSubview:appDelegate.columnController.view]; [srclViewMainContent addSubview:appDelegate.whatsOnController.view]; currentVisisbleController = appDelegate.homeController; [self resetAllSizes]; [super viewDidLoad];
}
在上述情况下,虽然我得到所有取向委托方法被称为在碱VC而不是在其他四个VC ..所以我不得不调整像
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
DNAppDelegate *appDelegate = (DNAppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate.homeController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
[appDelegate.newsListController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
[appDelegate.columnController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
[appDelegate.whatsOnController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
DNAppDelegate *appDelegate = (DNAppDelegate*)[UIApplication sharedApplication].delegate;
currentPageOffset = srclViewMainContent.contentOffset.x/srclViewMainContent.frame.size.width;
[appDelegate.homeController willRotateToInterfaceOrientation:toInterfaceOrientation duration:(NSTimeInterval)duration];
[appDelegate.newsListController willRotateToInterfaceOrientation:toInterfaceOrientation duration:(NSTimeInterval)duration];
[appDelegate.columnController willRotateToInterfaceOrientation:toInterfaceOrientation duration:(NSTimeInterval)duration];
[appDelegate.whatsOnController willRotateToInterfaceOrientation:toInterfaceOrientation duration:(NSTimeInterval)duration];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
DNAppDelegate *appDelegate = (DNAppDelegate*)[UIApplication sharedApplication].delegate;
[self resetAllSizes];
CGRect visibleRect = CGRectMake(currentPageOffset*srclViewMainContent.frame.size.width, 0, srclViewMainContent.frame.size.width, srclViewMainContent.frame.size.height);
[srclViewMainContent scrollRectToVisible:visibleRect animated:NO];
[appDelegate.homeController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[appDelegate.newsListController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[appDelegate.columnController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[appDelegate.whatsOnController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
即在来自基本VC的相应VC上调用这些委托方法。我必须这样做,因为我的应用程序完全构建,后来我必须更改体系结构以允许在各种视图之间滚动,但是我已经通过使用四个View控制器实现了这些视图。
简而言之,直接添加到窗口的任何VC(也是导航控制器,选项卡栏控制器,分离视图控制器)都会将这些方向更改委托方法传播到后续VC,但View控制器不会将这些委托方法传递给VC下来泳道
我希望这能给你一些见解。如果您遇到任何优秀的解决方案,请将其作为答案发布,并与我们分享。
谢谢Rahul Sharma ......会试试这个。 – iOSDev
刚刚尝试过,但此方法没有在我的子视图中调用。是否需要所有的父视图都应该有这种方法? – iOSDev
不是的,这是我的假设,当你切换视图时它没有被调用,或者你忘记了添加两种方法,就像我在编辑的代码中显示的那样。 – Nit
更新:试图将此方法添加到所有视图。会发生什么是UI组件正确旋转。但我也在改变景观的背景图像,它不会改变bcoz的代码没有被调用。 UI组件是使用自动调整设置的。在这种情况下可以做些什么? – iOSDev