0

このコードをすべてのviewControllerに入れました:

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

    if (orientation == UIInterfaceOrientationLandscapeRight) {
        CGAffineTransform transform = self.view.transform;

        // Use the status bar frame to determine the center point of the window's content area.
        //CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
        //CGRect bounds = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.origin.x);
        CGPoint center = CGPointMake(320/2, 480/2);

        // Set the center point of the view to the center point of the window's content area.
        self.view.center = center;

        // Rotate the view 90 degrees around its new center point.
        transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
        self.view.transform = transform;
    }   

そして私も持っています:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations

    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

コードが正常に機能していることはわかりますが、まれに、ビューをメイン ビューに戻した後、メイン ビュー コントローラーがランドスケープ モードで回転しないことがあります。それが発生する可能性は非常にまれですが、これは私を悩ませています. また、iPhone でより頻繁に発生していることがわかります。シミュレーターでは、決して起こらないことを思い出しました。これについて考えられる原因は何ですか?前もって感謝します。

4

1 に答える 1

0

私のiPhoneプログラムの原因を見つけました。

考えられる原因の 1 つはメモリです。以下のこのメソッドは、システムのメモリが不足しているときに呼び出されます。

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

このメソッドが呼び出されると、「見えない」UIView がアンロードされます。このビューをもう一度表示しようとすると、デバイスが再読み込みしましたが、再読み込み時に呼び出されない場所にパラメーター (回転など) を設定したためかもしれません。以下を使用できます。

- (void)viewDidLoad {

    UIApplication* application = [UIApplication sharedApplication];
    application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;

    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation([MyMath radd:90]);
    landscapeTransform = CGAffineTransformTranslate (landscapeTransform, -80, 83);

    [self.view setTransform: landscapeTransform];
    [super viewDidLoad];
}

実際のデバイスで実際のメモリについて話しているため、デバイスで発生します。シミュレータを使用している場合は、「ハードウェア > メモリの警告をシミュレート」を使用できます。

于 2009-08-11T04:19:05.417 に答える