1

ipad アプリケーションを実行しています。起動時に mainview と aboutus ビューの 2 つのビューがあり、メインビューを rootcontroller のビュー (ウィンドウに追加されるビュー) だけに配置します。メインビューにはボタンがあり、これを押すとメインビューがスーパービューから削除され、代わりに aboutusview が表示されます。aboutus には、メインビューに戻る同様のボタンがあります。

ここで問題は回転 (向き) にあります。向きの変化を検出すると、表示されたビューを更新します。正常に動作します。(mainview と aboutusview の場合) しかし、ビューを 1 回回転させてから、2 番目のビューを表示しようとするとします。2番目のビューは自動サイズ調整されていないようです。

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);
}

私は何を間違っていますか?

4

0 に答える 0