2016-06-25 9 views
-1

私はuiview継承されphotoBroserを持っています?iOS版: `uiview`サポートの肖像画や風景の向きを聞かせする方法

@interface SDPhotoBrowser : UIView <UIScrollViewDelegate> 

しかし、今、私はphotoBroserサポートiphone 肖像画や風景を聞かせする必要がありますオリエンテーション、どのようにこれを行うには?

my photobroser

EDIT:私のアプリケーションでは、私のアプリは唯一uiviewある唯一の私photoBrowserで、portraitの向きをサポートし、私はportrait and landscapeの向きをサポートしたいです。

EDIT:私のphotoBrowserが却下した後、私はJ.Hunterの答えを適用し、そして彼の答えは、実際のコーディングで、非常に良いですが、私は私が私のphotoBrowserを解任portrait and landscape orientation .Whenを変更する機能を提案し、問題が、そこに来て、デバイスがlandscape orientationであるため、以下のコードを使用してデバイスportrait orientationとし、photoBrowserを閉じて、合理的に表示します。

//(force landscape:[self interfaceOrientation:UIInterfaceOrientationLandscapeRight];) 
//(force Portrait:[self interfaceOrientation:UIInterfaceOrientationPortrait];) 
+ (void)interfaceOrientation:(UIInterfaceOrientation)orientation 
{ 
    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { 
     SEL selector = NSSelectorFromString(@"setOrientation:"); 
     NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]]; 
     [invocation setSelector:selector]; 
     [invocation setTarget:[UIDevice currentDevice]]; 
     int val = orientation; 
     // from 2 
     [invocation setArgument:&val atIndex:2]; 
     [invocation invoke]; 
    } 
} 

この関数は、完全なsupport portrait and landscape orientationのコードで役に立ちます。

+1

UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeアプリのサポートの両方の肖像画ですと横向きか、縦向きのみサポートしていますか? –

+0

プロジェクトのルートにあるXcodeには、[一般]> [展開情報]> [デバイスオリエンテーション]があります。 –

+0

@ J.Hunter私は私の部分的な質問について謝罪し、私は私の質問にいくつかの記述を完了しています。 – lme

答えて

1

あなたのアプリでは、縦向きしかサポートされていません。特別ビューコントローラでは、ポートレートと風景の向きをサポートするために2つのステップが必要です。ただ

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 
    if (self.shouldRotation) { 
     return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape; 
    } 
    else { 
     return UIInterfaceOrientationMaskPortrait; 
    } 
} 

のように、- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)windowから
は、私はあなたがUIApplicationDelegateの配向方法を実装し、 'AppDelegate.m' は、
2. @property (nonatomic, assign) BOOL shouldRotation;という名前AppDelegate.hにプロパティを追加するのObjective-C

1を使用したとしこれで、任意のUIViewControllerで横向きの向きをサポートできます。

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    // enable landscape orientation 
    [UIApplication sharedApplication].delegate.shouldRoration = YES; 
} 

- (void)viewDidDisappear:(BOOL)animated { 
    [super viewDidDisappear:animated]; 

    // disable landscape orientation 
    [UIApplication sharedApplication].delegate.shouldRoration = NO; 
} 

役立つことがあります。
PSは、それを解決する別の方法があります:

  1. あなたのアプリのサポートのUIViewControllerオーバーライド- (UIInterfaceOrientationMask)supportedInterfaceOrientationsのすべてが、返すすべてのオリエンテーション
  2. UIInterfaceOrientationMaskPortraitまたは
+0

あなたの答えは私のために非常に重要です。ありがとう。 – lme

関連する問題