User Tools

Site Tools


ios-labs-s14:advanced-animations

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ios-labs-s14:advanced-animations [2014/02/25 15:25] (current)
mbarboi created
Line 1: Line 1:
 +=====Animations=====
 +There are multiple ways to make UIViews animate. The simplest of these is to use the UIView class method **animateWithDuration:​animations**.
  
 +As this is a class method you do not call it on your views, but on UIView itself. The first argument takes a double as the period of time in which to execute the animation. The second argument is a block. Within this block, change one or multiple fields of the frame property of the intended views.
 +
 +Example, assuming your animating view is called myView and you are moving it down the screen 100 pixels:
 +<​code>​
 +[UIView animateWithDuration:​0.25 animations:​^{
 +            CGRect oldframe = myView.frame;​
 +            oldFrame.origin.y = oldFrame.origin.y + 100;
 +            myView.frame = oldFrame;
 +        }];
 +</​code>​
 +
 +You cannot change a field of a CGRect without replacing the entire CGRect.
 +
 +The old frame of the view is first extracted, the y coordinate is modified, then assigned back to the view. The difference between the view's old position and new position on the screen will change over a period of .25 seconds.
ios-labs-s14/advanced-animations.txt ยท Last modified: 2014/02/25 15:25 by mbarboi