2016-05-01 9 views
0

UIImageViewは、ユーザーが携帯電話を回転させたときに回転しないようにするにはどうすればよいですか?AutoLayout - 回転しないUIImageView

ビューコントローラ内の他のビューはすべて通常どおり自動レイアウトで更新する必要がありますが、UIImageViewを一定にします。

どうすればこの問題を解決できますか?今、私はviewWillTransitionToSizeで画像を回転させていますが、それはひどい見て、LandscapeLeftLandscapeRight

答えて

-1

ありUIViewのは回転していないと魔法のフラグはませんが、あなたは次のコードで戻ってそれを回転させる可能性があるため考慮していません。 :

-(void) viewDidLoad { 
    [super viewDidLoad]; 
    // Request to turn on accelerometer and begin receiving accelerometer events 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 
} 

- (void)orientationChanged:(NSNotification *)notification { 
    // Respond to changes in device orientation 
    switch ([UIDevice currentDevice].orientation) 
    { 
     case UIDeviceOrientationLandscapeLeft: 
      self.img.transform = CGAffineTransformMakeRotation(-M_PI/2); 
      break; 
     case UIDeviceOrientationLandscapeRight: 
      self.img.transform = CGAffineTransformMakeRotation(M_PI/2); 
      break; 
     case UIDeviceOrientationPortrait: 
      self.img.transform = CGAffineTransformMakeRotation(0); 
      break; 
     case UIDeviceOrientationPortraitUpsideDown: 
      self.img.transform = CGAffineTransformMakeRotation(0); 
      break; 
     case UIDeviceOrientationFaceUp: 
      break; 
     case UIDeviceOrientationFaceDown: 
      break; 
     case UIDeviceOrientationUnknown: 
      break; 
    } 
} 

-(void) viewDidDisappear { 
    // Request to stop receiving accelerometer events and turn off accelerometer 
    [[NSNotificationCenter defaultCenter] removeObserver:self]; 
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 
} 
+0

これはイメージの正確なサイズを保持せず、回転中にも回転するように見えますが、これは非常に醜いです。 –

関連する問題