1

そのため、いくつかのビュー コントローラーで次のコードを使用して、向きの変化に応じてさまざまな方法で描画されるカスタム オブジェクトを実装しました。

何らかの理由で、次の 2 つのメソッドのこの特定の実装は機能しません。

- (void)awakeFromNib
{
    isShowingLandscapeView = NO;
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(orientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:[UIDevice currentDevice]];
}



- (void)orientationChanged:(NSNotification *)notification
{
    NSLog(@"Are we changing orientations?");
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
        !isShowingLandscapeView)
    {
        isShowingLandscapeView = YES;
        NSLog(@"Landscape!");

        /*

         // Landscape orientation
         [txtLoginID setFrame:CGRectMake(489, 200, 145, 30)];
         [txtPassword setFrame:CGRectMake(489, 235, 145, 30)];
         [loginLabel setFrame:CGRectMake(378, 203, 69, 21)];
         [pwdLabel setFrame:CGRectMake(378, 238, 80, 21)];
         loginButton.frame = CGRectMake(561, 273, 73, 30);

         // Set iPad landscape background
         background.frame = CGRectMake(0, 0, 1024, 748);
         [background setContentMode:UIViewContentModeScaleToFill];
         [background setImage:[UIImage imageNamed:@"ipadLandscape.jpg"]];
         [self.view addSubview:background];
         */
    }
    else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
             isShowingLandscapeView)
    {
        isShowingLandscapeView = NO;
        NSLog(@"Portrait!");

        /*
         // Portrait orientation
         txtLoginID.frame = CGRectMake(367, 254, 145, 30);
         txtPassword.frame = CGRectMake(367, 289, 145, 30);
         loginLabel.frame = CGRectMake(256, 257, 69, 21);
         pwdLabel.frame = CGRectMake(256, 292, 80, 21);
         loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
         loginButton.frame = CGRectMake(439, 327, 73, 30);

         // Set iPad portrait background
         background.frame = CGRectMake(0, 0, 768, 1004);
         [background setContentMode:UIViewContentModeScaleToFill];
         [background setImage:[UIImage imageNamed:@"ipadPortrait.jpg"]];
         [self.view addSubview:background];
         */
    }
}

これが機能しない理由について何か考えはありますか? 私のログステートメントは何も生成しないようです。

4

2 に答える 2

2

ラグについては、代わりに次の方法を試してください。

- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
于 2013-04-12T19:37:21.867 に答える
1

メソッドをオーバーライドすることで、View Controllerから直接通知をサブスクライブしなくても、これを行うことができると思いますdidRotateFromInterfaceOrientation:こちらのApple ドキュメントを参照してください。

于 2013-04-12T19:24:30.547 に答える