【发布时间】:2014-05-06 03:56:56
【问题描述】:
我希望在屏幕上设置一个 50x50 的 UIImage 动画,就像触摸一个按钮时的心电图信号一样。
我正在使用一个测试项目,并且无需按钮即可运行:
@interface IPhoneViewController ()
@end
@implementation IPhoneViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[UIView animateWithDuration:1.0F animations:^{
CGPoint oldPosition = self.dot.layer.position;
CGPoint newPosition = CGPointMake(oldPosition.x + 170, oldPosition.y);
self.dot.layer.position = newPosition;
}];
}
@end
当我在此代码上方添加行- (IBAction)onButtonPressed:(id)sender; { 时,会在-(void)viewDidAppear:(BOOL)animated { 行创建一个错误,指出“使用未声明的标识符'viewDidAppear'”。
首先,如何使用按钮启动动画,其次,我想像 ECG 机器那样以上下运动改变动画的方向,但是如果我在第一个之后添加另一组方向,只执行最后的指令。
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[UIView animateWithDuration:1.0F animations:^{
CGPoint oldPosition = self.dot.layer.position;
CGPoint newPosition = CGPointMake(oldPosition.x + 170, oldPosition.y);
self.dot.layer.position = newPosition;
}];
[UIView animateWithDuration:1.0F animations:^{
CGPoint oldPosition = self.dot.layer.position;
CGPoint newPosition = CGPointMake(oldPosition.x + 10, oldPosition.y - 100);
self.dot.layer.position = newPosition;
}];
}
感谢您的帮助。
【问题讨论】:
标签: ios objective-c animation uibutton uiimage