6

多くのビューを持つアプリケーションがあります。デバイスを回転させたときに、いくつかのビューだけを横向きに回転できるようにしたいです。(BOOL)shouldAutorotateToInterfaceOrientationアプリのすべてのビューが回転するため、使用できないことがわかりました。Stack Overflow でこの問題の解決策を見つけましたが、別の問題に対処する必要があります。

デバイスを回転させるとビューが回転しますが、まだ縦向きモード (まっすぐ上下) にあるかのようにビューが表示されます。ビューの上下が切り取られています。ビューを回転させ、新しい向きに合わせてサイズを調整する方法はありますか? これも見つけましが、動作させることができませんでした。

そのビューのコードは次のとおりです。

@implementation businessBank
@synthesize webView, activityIndicator;


- (void)viewDidLoad {

    [super viewDidLoad];
    NSString *urlAddress = @"website_url";

    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [webView loadRequest:requestObj];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(didRotate:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];

}
- (void)didRotate:(NSNotification *)notification {

    UIDeviceOrientation orientation = [[notification object] orientation];

    if (orientation == UIDeviceOrientationLandscapeLeft) {
        [self.view setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)];
    } else if (orientation == UIDeviceOrientationLandscapeRight) {
        [self.view setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
    } else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
        [self.view setTransform:CGAffineTransformMakeRotation(M_PI)];
    } else if (orientation == UIDeviceOrientationPortrait) {
        [self.view setTransform:CGAffineTransformMakeRotation(0.0)];
    }
}
4

1 に答える 1

3

向きに合わせて伸縮する非常に基本的なアプリを使用していない限り、いずれにしても自動サイズ変更はうまく機能しません。2 つの向きに対して 2 つの別々のビューを作成する必要があります。

ビューの自動サイズ変更のヘルプについては、次のチュートリアルを確認してください。

http://theappleblog.com/2009/04/08/iphone-dev-sessions-how-to-make-an-orientation-aware-clock/

ビューを切り替えるより堅牢な方法を使用するには、このチュートリアルが役立ちます。

http://icodeblog.com/2008/08/03/iphone-programming-tutorial-transitioning-between-views/

于 2010-03-31T19:17:31.110 に答える