首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为iphone/ipad处理图像旋转的正确方法是什么?

为iphone/ipad处理图像旋转的正确方法是什么?
EN

Stack Overflow用户
提问于 2012-07-31 12:49:50
回答 1查看 1.5K关注 0票数 3

我有两张图片,一张是纵向模式,另一张是横向模式。当移动设备视图旋转时,切换这些图像的最佳方式是什么?

目前我只显示肖像图像。当设备旋转到横向模式时,肖像图像只是被拉伸。

我是否应该在方向旋转处理程序中进行检查,并简单地将图像重置为正确的方向图像(即,根据方向手动设置)?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-31 13:43:02

我找到了三种方法,我认为最后一种更好

1:自动调整大小

示例:

代码语言:javascript
复制
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

示例:

代码语言:javascript
复制
-(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的自动调整大小设置为自动填充屏幕

示例:

代码语言:javascript
复制
-(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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11733279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档