在iPhone SDK上实现动画的最佳方式? [英] Best way to implement animation on iPhone SDK?

查看:111
本文介绍了在iPhone SDK上实现动画的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何通过移动/调整UIView来实现基本动画。但是,以下两个动画似乎有点复杂。

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

1)想象一下汽车游戏,当你按下踏板按钮时,速度表会旋转。如何将条形填满圆形的动画?

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)第二个动画更容易描述。如何在数字向下滑动的情况下增加数字动画,新数字从顶部出现,类似于老虎机。

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.

推荐答案

对于你的第一个问题,我认为CGAffineTransform将是你要走的路。使用这个,我认为这样的东西可以工作:

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

这篇关于在iPhone SDK上实现动画的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆