我试图让一个UIView
动画作为浮动对象,或作为气球:D UIView
在屏幕的中间,我希望它保持随机浮动它的第一个启动点。没有穿过屏幕或类似的东西,只是漂浮在它周围5个像素的区域。如何动画浮动UIView在ObjectiveC
有什么建议吗? :d
我尝试这样做:
[UIView animateWithDuration:0.1
delay:0.0
options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction
animations:^{
myCircleUIView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator], [self randomFloatingGenerator]);
}
completion:NULL];
randomFloatingGenerator
生成-5之间的数字和5问题是,它仅执行一次,并保持着相同的随机值的重复。
EDIT1: 现在,我已经试过这
-(void)animationLoop{
[UIView animateWithDuration:1.0
animations: ^{ myCircleUIView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator], [self randomFloatingGenerator]); }
completion:
^(BOOL finished) {
[UIView animateWithDuration:1.0
animations:^{ myCircleUIView.transform = CGAffineTransformMakeTranslation(0,0);
}
completion:
^(BOOL finished) {[self animationLoop];}];
}];
但它仍然没有工作,在动画....嗳哟......我想我做了一些愚蠢的错误,我需要第二组眼睛帮助我。
EDIT2: 修正了它。
-(void)animationLoop{
CGPoint oldPoint = CGPointMake(myCircleUIView.frame.origin.x, myCircleUIView.frame.origin.y);
[UIView animateWithDuration:1.0
animations: ^{ myCircleUIView.frame = CGRectMake(myCircleUIView.frame.origin.x + [self randomFloatingGenerator], myCircleUIView.frame.origin.y + [self randomFloatingGenerator], myCircleUIView.frame.size.width, myCircleUIView.frame.size.height); }
completion:
^(BOOL finished) {
[UIView animateWithDuration:1.0
animations:^{ myCircleUIView.frame = CGRectMake(oldPoint.x, oldPoint.y, myCircleUIView.frame.size.width, myCircleUIView.frame.size.height);}
completion:
^(BOOL finished) {[self animationLoop];}];
}];
}
感谢您的帮助。
EDIT 3:
有人张贴增强的代码。
使用的NSTimer并调用上面它的代码... – 2014-09-10 11:06:10