0

I have lot of UiImageViews on my UIView and I create/place them differently based on Ipad or iPhone co-ordinates. Here is my current logic to create Frames for these 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;

}

I do lot of UIImageView animations by passing an array of images to UIImageView.animationImages through out my app. Now what is the best way to handle such scenarios with iPhone 5 compatibility?

Do I add one more else condition inside if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) to handle iPhone 5 by calculating its co-ordinates or there is a better way. I would greatly appreciate your suggestions.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Alex
  • 833
  • 3
  • 15
  • 28

1 Answers1

1

You have 2 options here:

Option 1:

Add a conditional statement for iPhone 5 inside your else statement

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);
    }
}

Option 2:

Use Auto-layout. You can get started on auto-layout here:
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
http://www.raywenderlich.com/20897/beginning-auto-layout-part-2-of-2

Bijoy Thangaraj
  • 5,434
  • 4
  • 43
  • 70