我正在做一个 ipad 应用程序,其中我在启动时说了两个视图 mainview 和 aboutus 视图我将 mainview 单独放在 rootcontroller 的视图(添加到窗口中的视图)中。并且在主视图上有一个按钮,按下该按钮时,将从超级视图中删除主视图并改为放置 aboutusview。aboutus 有一个类似的按钮,可以让我们回到主视图。
现在问题在于旋转(方向)。当我检测到方向变化时,我会更新显示的视图。工作正常。(对于 mainview 和 aboutusview)但是如果我旋转一次任何视图,然后尝试查看第二个视图。似乎第二个视图没有自动调整大小。
rootViewController 中的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
_currentOrientation=UIDeviceOrientationPortrait;
[self.view addSubview:_mainView];
[_splashView removeFromSuperview];
}
-(void)viewDidAppear:(BOOL)animated
{
_currentView = _mainView;
}
-(void)toggleMainPage
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:[self view] cache:YES];
[_infoView removeFromSuperview];
[self.view addSubview:_mainView];
_currentView=_mainView;
[self transformViewAccordingToOrientation:_currentOrientation];
[UIView commitAnimations];
}
-(void)toggleAboutPage
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:[self view] cache:YES];
[_mainView removeFromSuperview];
[self.view addSubview:_infoView];
_currentView=_infoView;
[self transformViewAccordingToOrientation:_currentOrientation];
[UIView commitAnimations];
}
-(void) transformViewAccordingToOrientation:(UIDeviceOrientation)toInterfaceOrientation
{
if(toInterfaceOrientation == UIDeviceOrientationPortrait)
{
[_mainBtnCustom setBackgroundImage:[UIImage imageNamed:@"main.png"] forState:UIControlStateNormal];
_infoImage.image = [UIImage imageNamed:@"about.png"];
}else
{
[_mainBtnCustom setBackgroundImage:[UIImage imageNamed:@"mainr.png"] forState:UIControlStateNormal];
_infoImage.image = [UIImage imageNamed:@"aboutr.png"];
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self transformViewAccordingToOrientation:toInterfaceOrientation];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
_currentOrientation = [UIDevice currentDevice].orientation;
[self transformViewAccordingToOrientation:_currentOrientation];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (_currentOrientation !=interfaceOrientation);
}
我究竟做错了什么?