0

XCode 4.6 と iOS 6.1 を使用しています。しかし、私のアプリは向きを変えません。pList で方向をサポートするようにアプリを設定し、方向変更メソッドを追加しました。それでもアプリの向きは変わりません。

ここに画像の説明を入力

ここに画像の説明を入力

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

}

私は TabBarController を使用しており、このコードを使用して追加しています。

self.window.rootViewController = self.tabController;

iOS 6 シミュレーターではすべて正常に動作しますが、iOS 5 では動作しません。

4

4 に答える 4

2

向きをチェックするコードが機能しているかどうか

コード ::

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
    ......
}

チェック方法 ::

-(void)orientationChanged {

   NSLog(@"Orientation Changed..!!");
}

方向変更メソッドのコード

PCH ファイルでは、

#define IOS_OLDER_THAN_6        ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0 )
#define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 )

.m ファイルでは、

//For Less than IOS 6

#ifdef IOS_OLDER_THAN_6
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation
{
   return toInterfaceOrientation;
}
#endif

// For Newer than IOS 6.
#ifdef IOS_NEWER_OR_EQUAL_TO_6
-(BOOL)shouldAutorotate
{
   return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
   return (UIInterfaceOrientationMaskAll);
}
#endif

うまくいけば、それはあなたに役立つでしょう.

ありがとう。

于 2013-03-15T12:04:22.147 に答える
1

viewController の向きの変更を制御および構成するには、次の 2 つの新しいメソッドを使用する必要があります。

- (BOOL)shouldAutorotate {
    return YES;    
}

- (NSUInteger)supportedInterfaceOrientations {    
    return (UIInterfaceOrientationMaskPortrait | 
            UIInterfaceOrientationMaskPortraitUpsideDown);
}

実装している方法は iOS 5.x 用ですが、この回答で言及されている方法は iOS 6.x 用です。両方の OS バージョンの互換性が必要な場合は、viewController に両方のメソッドを実装する必要があります。

于 2013-03-15T11:49:57.900 に答える
0

tabBar を使用しているので、このコードを AppDelegate の @end の下部に配置します。

@implementation UITabBarController (Rotation)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{   
    if ([self.selectedViewController isKindOfClass:[UINavigationController class]]) {
        UIViewController *rootController = [((UINavigationController *)self.selectedViewController).viewControllers objectAtIndex:0];
        return [rootController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }
    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

@end

これが役立つことを願っています。

于 2013-03-16T05:29:49.053 に答える
0

最上位のナビゲーション コントローラーで、次を定義します。

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

そしてあなたの次のviewControllerで:

-(BOOL)shouldAutorotate {return YES;}

-(NSUInteger)supportedInterfaceOrientations {  
return (UIInterfaceOrientationMaskPortrait | 
        UIInterfaceOrientationMaskPortraitUpsideDown);
}
于 2013-03-15T12:34:32.287 に答える