iphone/ipad处理图像旋转的正确方法是什么?
问题描述:
我有2个图像,一个是纵向模式,另一个是横向模式。 移动设备视图旋转发生时切换这些图像的最佳方式是什么?iphone/ipad处理图像旋转的正确方法是什么?
目前我只显示肖像图像。当设备旋转到横向模式时,肖像图像会被简单拉伸。
我应该在方向旋转处理程序中检查并简单地将图像重置为正确的方位图像(即根据方向手动设置)??
谢谢!
答
我发现了三个ways.I想到最后一个是更好
1:会自动调整大小
例子:
UIImageView *myImageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage.png"]];
myImageView.frame = self.view.bounds;
myImageView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight
myImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:myImageView];
[imageView release];
2:CGAffineTransformMakeRotation
例子:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
myImageView.transform = CGAffineTransformMakeRotation(M_PI/2);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
myImageView.transform = CGAffineTransformMakeRotation(-M_PI/2);
}
else {
myImageView.transform = CGAffineTransformMakeRotation(0.0);
}
}
3:myImageView的自动调整大小设置为自动填充屏幕在界面生成器
实施例:
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)){
myImageView.image = [UIImage imageNamed:@"myImage-landscape.png"];
} else if((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)){
myImageView.image = [UIImage imageNamed:@"myImage-portrait.png"];
} }
看到更多的解决方案here
developer.apple溶液是here