あり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];
}
これはイメージの正確なサイズを保持せず、回転中にも回転するように見えますが、これは非常に醜いです。 –