0

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

- (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,或者有更好的方法。我将非常感谢您的建议。

4

1 回答 1

1

您在这里有 2 个选项:

选项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

于 2012-09-25T09:01:57.980 回答