0

One concern over a universal app I currently developing. I just finishing with functionality development and need to add eye candy (animations). Now wondering in a single iPhone or iPad app I would just play and set frame, bounds, to move a View, layer etc with hardcoded values.

Now how would you handled the different device frame and bounds? Meaning you want to move a UIImageView from outside the parent View bounds and make it come to a position. Handling differently while testing what device we running at?

Thank you.

George Taskos
  • 8,324
  • 18
  • 82
  • 147

1 Answers1

1

You could add a method in your AppDelegate,

- (BOOL) ISIPAD {
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
}

And refer to that each time you are making animations. If you then have some variables in your class with the width of the screen and so, you only need to check for this in either the viewDidLoad, or your init method. Then you could use the dynamic variables to do your animations. To place a button in the middle of the screen, you could do:

[UIView animateWithDuration:1.0 animations:^{
    UIButton *yourButton;
    yourButton.frame = (CGRect){.origin = CGPointMake(screenwidth/2.0f-yourButton.frame.size.width/2.0f, screenheight/2.0f - yourButton.frame.size.height/2.0f), .size = yourButton.frame.size};
}];

Considering the screenvariables are set in your init or viewDidLoad method, this will put your button in the middle of your screen.

Martol1ni
  • 4,684
  • 2
  • 29
  • 39
  • Thank you, I thought it should be done this way. Just wondering if its better to seperate the projects than define logic, but as far as it concerns just some values in the screens, guess it shouldn't be bad option/design. Thinking of creating helper class that returns screen width and values needed for animation depended the Storyboard ViewController you currently are. Thank you for your time. – George Taskos Nov 22 '12 at 15:14