什么是处理为iPhone / iPad的图像旋转的正确方法?(What is the proper

2019-09-20 11:48发布

我有2个图像,一个在纵向模式下,和其他在横向模式。 什么是当移动设备视图旋转发生切换这些图像的最佳方式?

目前,我只显示该肖像图像。 而当设备旋转为横向模式的人像图像被拉伸简单。

如果我的方向旋转处理器内检查和简单的图像恢复到正确的取向图像(即它集手动基于取向)?

谢谢!

Answer 1:

我发现了三个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"];
} }

看到更多的解决方案, 在这里

developer.apple的解决方案是在这里



文章来源: What is the proper way to handle image rotations for iphone/ipad?