1

UIDeviceOrientationDidChangeNotification現在、iOS 5 で画面の回転に問題があります。iOS 6 ではすべて正常に動作しますが、iOS 5 では通知が呼び出されても回転が機能しません。

私は使用Storyboardしていますが、これが私の様子ViewControllerです:

ここに画像の説明を入力

画面を回転させるには、次の方法を使用します。

CustomTabBarViewController.mm ( UITabBarController)

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    if (isLandscapeOK) {
        // for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (isLandscapeOK) {
        // for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
        return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown);
    }
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

TabBarItemController.mm ( UINavigationView)

-(BOOL)shouldAutorotate
{
    return [self.topViewController shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

LoyaltyListController.mm ( UIViewController)

- (void) didRotate:(NSNotification *)notification
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

    if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
    {
        self.navigationController.navigationBarHidden = YES;
        [self hideTabBar:self.tabBarController];
        portraitView.hidden = YES;
        landscapeView.hidden = NO;
    }
    else if (orientation == UIDeviceOrientationPortrait)
    {
        self.navigationController.navigationBarHidden = NO;
        [self showTabBar:self.tabBarController];
        portraitView.hidden = NO;
        landscapeView.hidden = YES;
        [notificationView setFrame:CGRectMake(0, - (notificationView.frame.size.height + 40), notificationView.frame.size.width, notificationView.frame.size.height)];
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
    [(CustomTabBarViewController*)[self tabBarController] setLandscapeOK:YES];
}

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown);
}

iOS 5 の画面は次のとおりです。

ポートレート:

ここに画像の説明を入力

横: (回転しませんでした)

ここに画像の説明を入力

これは次のようになります。

ここに画像の説明を入力

何か案が?

4

2 に答える 2

1

iOS 5 の場合- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)

iOS 6 では非推奨ですが、使用しても問題ありません。iOS 5.0 以下の場合にのみ呼び出されます。

更新: UIInterfaceOrientationMaskAllButUpsideDownは UIInterfaceOrientation 列挙型ではありません。iOS 6 ではマスキングを使用してマスク値を指定し、サポートしたい向きの組み合わせを指定しますが、iOS 5 では.

interfaceOrientaion が次のいずれかであるかどうかを確認する必要があります

UIInterfaceOrientationLandscapeLeft,UIInterfaceOrientationLandscapeRight, UIInterfaceOrientationPortrait or UIInterfaceOrientationPortraightUpsideDown.

サポートするすべての方向に基づいて、YES または NO を返します。

あなたの場合、使用:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
 /* If you are supporting all, simply return YES,

 if you aren't supporting any return NO, otherwise Use || and check which ones you wanna return YES for.
 In this case you wanna support all except UpsideDown hence use this. */
}
于 2013-07-22T16:05:43.883 に答える
-1

すべてのオリエンテーション iOS 5 以前と iOS での非推奨をサポートするために YES を返す必要があり、iOS 6 では呼び出されません。iOS6 メソッドは既に正しく実装されています。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
于 2013-07-22T16:06:21.153 に答える