Best way to implement animation on iPhone SDK?

2019-04-01 05:03发布

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

1) Imagine a car game, where when you press on the pedal button the speedometer spins. How to do the kind of animation where the bar "fills up" in a circular shape?

2) The second animation is easier to describe. How to do the animation of numbers increasing where the number slides down and the new number appears from the top similar to a slot machine.

1条回答
Juvenile、少年°
2楼-- · 2019-04-01 05:18

For your first question, I would think that CGAffineTransform would be the way to go. Using this, I would think something like this could work:

// 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)];   
}
查看更多
登录 后发表回答