Best way to implement animation on iPhone SDK?

醉酒当歌 提交于 2019-12-05 02:23:21

问题


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:


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


来源:https://stackoverflow.com/questions/970939/best-way-to-implement-animation-on-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!