2010-10-21 124 views
0

我想要在视图中使用图像,像HTML中的选取框一样移动,从一端移动到另一端。 任何人都可以为我提供该代码如何做到这一点。图像与动画在iphone

在此先感谢n请帮我解决这个问题。

+1

对不起,给我一个代码的问题一般不欢迎在这里。你必须尝试自己做一些事情,并询问你在这个过程中遇到的具体问题... – Vladimir 2010-10-21 10:32:07

回答

1

这是其在iOS系统中引入的新模块API 4.0 使用这个,如果你还没有在4.0

CABasicAnimation *theAnimation;   
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; 
theAnimation.duration=1; 
theAnimation.repeatCount=2; 
theAnimation.autoreverses=YES; 
theAnimation.fromValue=[NSNumber numberWithFloat:0]; 
theAnimation.toValue=[NSNumber numberWithFloat:-60]; 
[view.layer addAnimation:theAnimation forKey:@"animateLayer"]; 

这段代码移动视图60个像素向左,然后回到它原来的位置 [请不要忘记投票,如果你发现这个答案有用:-)]

+0

是的兄弟,这是我使用iPhone 3.2.1 SDK的原因,所以得到的问题。我会尝试它tommorow.Sure我会投票给你,但我需要15名声誉,我有11但有人投我倒。 – Sabby 2010-10-22 14:30:11

+0

Hummm现在明白了,谢谢亲爱的........ – Sabby 2010-11-04 05:32:47

0

使用的UIView的过渡效果..

[UIView AnimateWithDuration: delay: options: animations: completion: ]; 

梅索德。 重复转换有一些很好的效果。

+0

感谢好友,我将使用这种方法... – Sabby 2010-10-22 11:57:41

+0

[UIView AnimateWithDuration:3 delay:1 options:nil animations:@“logo(1 ).png“,@”sabby.png“完成:YES];我尝试过这样但它显示警告讯息。请让我知道错误在哪里。 – Sabby 2010-10-22 12:03:10