0

私の iPhone アプリケーションはナビゲーション ベースで、画像を表示するための縦向きのみのビューと 1 つの横向きのみのビューが多数含まれています。したがって、デバイスが縦向きモードに配置されていても、この横向きのみのビューを横向きに自動的に回転させたいと思います。

したがって、そのビューのコントローラーで行ったことは次のとおりです。

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
}

- (void)viewWillAppear:(BOOL)animated
{
 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
 [self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];

 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

 _originalTransform = [[appDelegate navigationController].view transform];
 _originalBounds = [[appDelegate navigationController].view bounds];
 _originalCenter = [[appDelegate navigationController].view center];

 CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
 landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +80.0, +100.0);

 [[appDelegate navigationController].view setTransform:landscapeTransform];

 [appDelegate navigationController].view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
 [appDelegate navigationController].view.bounds  = CGRectMake(0.0, 0.0, 480.0, 320.0);
 [appDelegate navigationController].view.center  = CGPointMake (240.0, 160.0);

 [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
 }
}

- (void)viewWillDisappear:(BOOL)animated
{ 
 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
 [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];

 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
 [[appDelegate navigationController].view setTransform:_originalTransform];
 [[appDelegate navigationController].view setBounds:_originalBounds];
 [[appDelegate navigationController].view setCenter:_originalCenter];

 [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait; 
}

これで、そのビューが常に横向きモードで表示されるようになりました。しかし、問題が 1 つあります。このビューは、このスクリーンショットに示すように正しく配置されていません。

回転後にフレームを手動で設定しようとしましたが、役に立ちませんでした。また、1 つのビューを横向きのみに設定する方法の完全なガイドも見つかりませんでした。この問題で私を助けてください。

4

2 に答える 2

0

この男の投稿をチェックしてください。基本的に、ウィンドウの中心を中心に変形する必要があります。ステータスバーも回転させる必要があるようです。

別の方法はUIDevicesetDeviceOrientationを使用することですが、これはプライベートAPIであるため、優れたソリューションではありません。

于 2010-01-18T15:19:48.963 に答える
0

変換を適用した後、次の方法を使用してみてください。

[self.view sizeToFit];
于 2010-01-18T17:32:25.107 に答える