0

私の iPhone アプリでは、サポートされている向きを以下のスクリーン ショットのようにマークしました。

ここに画像の説明を入力

しかし、私は以下のコード(ios6)を使用しているため、自動回転に関するいくつかのビューを防ぎたいです

編集

-(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}


- (BOOL)shouldAutorotate
{
return NO;
 }

しかし、ビューはまだ回転しています。問題を解決するのを手伝ってください?

4

6 に答える 6

4

iOS 6.0 では、新しい回転メソッドが導入され、shouldAutorotateToInterfaceOrientation:.

iOS 6.0 より前のバージョンと iOS 6.0 以降のバージョンの両方をサポートするには、次のメソッドを実装する必要があります。

// Do as many checks as you want to allow for other orientations here for pre-iOS 6

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

// You can return YES here as this still checks supportedInterfaceOrientations
// before rotating, or you can return NO to 'lock' the view in whatever it's in... 
// Making sure to return the appropriate value within supportedInterfaceOrientations

- (BOOL)shouldAutorotate
{
    return YES;
}

// return supported orientations, bitwised OR-ed together

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

編集-あなたがの階層UIViewController内にある場合UINavigationController

ビュー コントローラーがUINavigationControllerのビュー階層内にある場合、回転メソッドは実際には (ビュー コントローラーではなく) ナビゲーション コントローラーで呼び出されます...これは私の意見では Apple によって面白く実装されましたが、許可するためにできることは次のとおりです。代わりにこれらのメソッドに応答するView Controller-

UINavigationController次の方法でカテゴリを作成します。

// UINavigationController+Additions.h file

@interface UINavigationController (Additions)
@end




// UINavigationController+Additions.m file

#import "UINavigationController+Additions.h"

@implementation UINavigationController (Additions)

- (BOOL)shouldAutorotate
{
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    UIViewController *viewController = [self topViewController];

    if ([viewController respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)])
    {
        return [viewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
    }

    return [super shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}

- (NSUInteger)supportedInterfaceOrientations
{
    UIViewController *viewController = [self topViewController];

    if ([viewController respondsToSelector:@selector(supportedInterfaceOrientations)])
    {
        return [viewController supportedInterfaceOrientations];
    }

    return [super supportedInterfaceOrientations];
}

@end

EDIT 2 - あなたが aのタブUIViewController内にある場合UITabBarController

View Controller がUITabBarControllerのタブ内にある場合、同じ問題があります。

もう一度、カテゴリを on に作成して、UITabBarController代わりに View Controller が応答できるようにします。

// UITabBarController+Additions.h file

@interface UITabBarController (Additions)
@end

// UITabBarController+Additions.m file

#import "UITabBarController+Additions.h"

@implementation UITabBarController (Additions)

- (BOOL)shouldAutorotate
{
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    UIViewController *selectedViewController = [self selectedViewController];

    if ([selectedViewController respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)])
    {
    return [selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
    }

    return [super shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}

- (NSUInteger)supportedInterfaceOrientations
{
    UIViewController *selectedViewController = [self selectedViewController];

    if ([selectedViewController respondsToSelector:@selector(supportedInterfaceOrientations)])
    {
        return [selectedViewController supportedInterfaceOrientations];
    }

    return [super supportedInterfaceOrientations];
}

@end

編集3

Objective-C カテゴリに関するリンクもいくつかあります。

http://macdevelopertips.com/objective-c/objective-c-categories.html

http://mobile.tutsplus.com/tutorials/iphone/objective-c-categories/

于 2013-02-26T05:11:08.997 に答える
0

特定のビューの向きを固定したい場合は、これを試してください。

-(BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait; //IOS_6
}

編集

タブバーがあるので、それを回避する必要があります。リンクを見てください。それが役立つことを願っています。

  1. リンク 1
  2. リンク 2
于 2013-02-26T05:15:09.557 に答える
0

私が見る限り、次のようにさらに2つのメソッドを書いたほうがいいでしょう

- (BOOL)shouldAutorotate
{
    return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
于 2013-02-26T05:16:00.000 に答える
0

向きを上下逆にしたいですか、それとも縦向きにしたいですか? 縦向き用にアプリを作成し、このコードを試してください(縦向きの場合は変更してください)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if(interfaceOrientation == UIInterfaceOrientationPortrait)
    return YES;

return NO;
}
于 2013-02-26T05:16:46.107 に答える
0

UINavigationControllerorが含まれる場合は、 /および をUITabBarControllerサブクラス化します。 UINavigationControllerUITabBarControlleroverriding supportedInterfaceOrientations

 #import "UINavigationController+Orientation.h"

 @implementation UINavigationController (Orientation)

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

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

@end  

// 為にUITabBarController

#import "UITabBarController+Orientation.h"

@implementation UITabBarController (Orientation)

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // You do not need this method if you are not supporting earlier iOS Versions
    return [self.selectedViewController  shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

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

-(BOOL)shouldAutorotate
{
    return YES;
}

@end

現在、iOS コンテナー (UINavigationController など) は、自動回転する必要があるかどうかを判断するために、子に相談しません。
サブクラス化の方法
1. 新しいファイルを追加 (Objective c-category 配下 cocoa touch)
2. Category: Orientation Category On: UINavigationController
3. に上記のコードを追加UINavigationController+Orientation.m

于 2013-02-26T05:33:27.210 に答える
0

shouldAutorotateToInterfaceOrientationiOS 6 で廃止されました。

詳細については、この質問の回答を確認してください。

于 2013-02-26T05:11:02.117 に答える