我有一个UIImageView,它在视图加载时移动。 它首先进入+100,然后将BOOL设置为已完成。
当BOOL设置为完成时,它将执行另一个动画,将UIImageView放回原始位置。当我的UIImageView回到它的原始位置时,它应该再次开始整个事情。这种重复应永远持续下去!我怎么能这样做?
这是我的代码:
[UIView animateWithDuration:0.5
animations:^
{
//move up
Person.center = CGPointMake(Person.center.x, Person.center.y +100);
}
completion:^(BOOL completed)
{
if (completed)
{
//completed move up..now move down
[UIView animateWithDuration:0.5
animations:^
{
Person.center = CGPointMake(Person.center.x, Person.center.y -100);
}
];
}
}];
答案 0 :(得分:0)
试试这段代码......
-(void)repeatForever
{
[UIView animateWithDuration:0.5
animations:^
{
//move up
Person.center = CGPointMake(Person.center.x, Person.center.y +100);
}
completion:^(BOOL completed)
{
if (completed)
{
//completed move up..now move down
[UIView animateWithDuration:0.5 animations:^{
Person.center = CGPointMake(Person.center.x, Person.center.y -100);
} completion:^(BOOL finished) {
[self repeatForever];
}];
}
}];
}