2016-05-04 22 views
2
+(CGFloat)maxTextWidth 
{ 
    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) 
    { 
     if(UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) 
      { 
     return 220.0f; 
      } 
      else 
      { 
       return 400.0f; 
      } 
    } 
    else 
    { 
     if(UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) 
     { 
     return 400.0f; 
     } 
    else 
    { 
     return 700.0f; 
    } 
    } 
} 

私のデバイスが上記の方法でポートレートの値を返すと、ポートレートの値が返されますが、ポートレートの値が返されることがあります。私のデバイスは常に縦向きです。iOSでデバイスの向きが正しく動作しない

答えて

3

..私は、私はクラスのメソッドとコードの上を使用しているので、私は、デバイスの向きに応じて最大のテキスト幅を返すようにチャット上で動作

+(CGFloat)maxTextWidth 
{ 
    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone) 
    { 
     if([UIApplication sharedApplication].statusBarOrientation==UIInterfaceOrientationPortrait) 
      { 
     return 220.0f; 
      } 
      else 
      { 
       return 400.0f; 
      } 
    } 
    else 
    { 
     if([UIApplication sharedApplication].statusBarOrientation==UIInterfaceOrientationPortrait) 
     { 
     return 400.0f; 
     } 
    else 
    { 
     return 700.0f; 
    } 
    } 
} 
+0

ありがとうございました。私の問題を解決しました。:) –

+0

私は、UIDeviceOrientationIsPortraitがiOS 11で問題として助けられました。 –

0

あなたは

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

を使用していないか、この

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

またはこの

-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 

これらの方法は、任意の向きの変化を検出に使用することができますなぜ。 これらのメソッドでのUIの変更を設定します。

+0

あなたのコードと同じように動作します.... –

1

このコードをviewdidloadにコピーします。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didrotatedevice:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

とあなたのクラスでこのメソッドをコピー

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


    if (orientation == UIDeviceOrientationLandscapeLeft) 
    { 
      NSLog(@"Landscape Left!"); 

    } 
    else if (orientation == UIDeviceOrientationLandscapeRight) 
    { 
     NSLog(@"Landscape Right!"); 

    } 
    else 
    { 
      NSLog(@"Potrait!"); 

    } 
    } 

は、あなたが疑問を持っている場合は、私に教えてください?代わりに、デバイスの向きのあなたのif文のチェックステータスバーの向きで

関連する問題