AutoLayout - 不旋转的UIImageView

时间:2016-05-01 18:33:42

标签: ios uiimageview autolayout

当用户旋转手机时,如何让eval $(docker-machine.exe env <name of your machine>) 不旋转?

视图控制器中的所有其他视图应该正常更新为自动布局,但我希望UIImageView保持不变。

我怎样才能做到这一点?现在我正在UIImageView中旋转图像,但这看起来很糟糕,并不考虑viewWillTransitionToSizeLandscapeLeft

1 个答案:

答案 0 :(得分:-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];
}