我正在做一个ipad应用程序,其中我说了两个视图 mainview和aboutus视图 在启动时,我将mainview放在rootcontroller的视图(添加到窗口的视图)中。 主视图上有一个按钮,当按下该按钮时,将从superview中删除主视图并改为使用aboutusview。 aboutus有一个类似的按钮,让我们回到主视图。
现在的问题在于旋转(方向)。 当我检测到方向变化时,我更新显示的视图。工作良好。 (主视图和aboutusview) 但如果我旋转一次任何视图,然后尝试看到第二个视图。似乎第二种观点不是自动调整。
rootViewController中的CODE:
- (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);
}
我做错了什么?