gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 19:55:00 26 4
gpt4 key购买 nike

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

目前我只显示肖像图像。当设备旋转到横向模式时,纵向图像会被简单地拉伸(stretch)。

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

谢谢!

最佳答案

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

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:在 Interface Builder 中将 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

关于iphone - 处理 iphone/ipad 图像旋转的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11733279/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com