我花了一段时间才理解这个概念。我不想创建相同的图像纵向和横向。这里的关键是CGAffineTransformMakeRotation
从你的 UIImageView 或任何 UIView 的原始状态旋转。这假设您的背景图像有方向。例如,您希望您的 UIImageView 保持原状,而其他对象的行为是正常的方向更改事件。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
backgroundImage.transform = CGAffineTransformMakeRotation(M_PI / 2);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
backgroundImage.transform = CGAffineTransformMakeRotation(-M_PI / 2);
}
else {
backgroundImage.transform = CGAffineTransformMakeRotation(0.0);
}
}
- (void)viewDidLoad {
[super viewDidLoad];
//set the UIImageView to current UIView frame
backgroundImage.frame = self.view.frame;
}