gpt4 book ai didi

ios - 与 iPhone 5 兼容的通用应用程序的 UIElements 放置

转载 作者:行者123 更新时间:2023-11-29 04:24:31 26 4
gpt4 key购买 nike

我的 UIView 上有很多 UiImageView,我根据 iPad 或 iPhone 坐标以不同的方式创建/放置它们。这是我当前为这些 UIImageView 创建框架的逻辑

- (void)setAnimationFrame:(NSString *)imageName iPadFrameX:(int)iPadX iPadFrameY:(int)iPadY iPhoneFrameX:(int)iPhoneX iPhoneFrameY:(int)iPhoneY imageSizePercentForiPad:(CGFloat)imageSizePercentForiPad imageSizePercentForiPhone:(CGFloat)imageSizePercentForiPhone  animationNumber:(int)animationNumber imageAnimationView:(UIImageView *)imageAnimationView{

int tagNumber;
tagNumber = [self getTagNumber:animationNumber];
UIImage *image = [UIImage imageNamed:imageName];
CGRect frame;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
frame = CGRectMake(iPadX, iPadY, image.size.width*imageSizePercentForiPad, image.size.height*imageSizePercentForiPad);
}
else
{
frame = CGRectMake(iPhoneX, iPhoneY, image.size.width*imageSizePercentForiPhone, image.size.height*imageSizePercentForiPhone);
}

imageAnimationView.frame = frame;
imageAnimationView.image = image;
imageAnimationView.tag = tagNumber;

}

我通过在我的应用程序中将图像数组传递给 UIImageView.animationImages 来完成很多 UIImageView 动画。现在,在兼容 iPhone 5 的情况下处理此类场景的最佳方法是什么?

我是否需要在 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 中添加一个其他条件来通过计算 iPhone 5 的坐标来处理它,或者有更好的方法。我非常感谢您的建议。

最佳答案

这里有两个选择:

选项 1:

在 else 语句中添加 iPhone 5 的条件语句

else {
if ([[UIScreen mainScreen] bounds].size.height == 568) {
// set the frame specific for iPhone 5
} else {
frame = CGRectMake(iPhoneX, iPhoneY, image.size.width*imageSizePercentForiPhone, image.size.height*imageSizePercentForiPhone);
}
}

选项 2:

使用自动布局。您可以在此处开始自动布局:
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
http://www.raywenderlich.com/20897/beginning-auto-layout-part-2-of-2

关于ios - 与 iPhone 5 兼容的通用应用程序的 UIElements 放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12536684/

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