Best way to implement animation on iPhone SDK?

I know how to implement basic animation by moving / resizing a UIView. However, the following two animations seem a bit complicated.

1) Imagine a car game where, when you press the pedal button, the speedometer rotates. How to make such an animation where the bar is "filled" with a round shape?

2) The second animation is easier to describe. How to animate numbers that increase where the number of slides is down, and the new number is displayed on top, as in a slot machine.

+3
source share
1 answer

, CGAffineTransform . , , - :

// BarView is a derived class from UIView that knows how to draw a "bar"
BarView view[NumBars];
for(int i = 0; i < NumBars; i++)
{
  // First place the view at the center of the instrument
  [view[i] setCenter:CGPointMake(InstrumentX, InstrumentY)];

  // Now translate the view InstrumentWidth units on the positive X-Axis
  CGAffineTransform translate = CGAffineTransformMakeTranslation(InstrumentWidth, 0);

  // Rotate the view about the origin by an angle related to which "bar" this is
  CGAffineTransform rotate = CGAffineTransformMakeRotation(i*AngleBetweenBars);

  // create a transform matrix from the translation and rotation matrices and apply it to the view
  [view[i] setTransform:CGAffineTransformConcat(translate, rotate)];   
}
+6

Source: https://habr.com/ru/post/1710086/


All Articles