动画固定在终点的自定义按钮

时间:2013-12-17 20:46:06

标签: ios animation button

已编辑问题:

所以我有一些自定义按钮(云)的代码,它们从右向左移动,并在点击时生成动画。

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Move UIView

    cloudAnimate.center = CGPointMake(400.0, 90.0);
    cloudAnimate1.center = CGPointMake(400.0, 150.0);
}


- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    [UIView animateWithDuration:10.0
                          delay:1.0
                        options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction
                     animations:^{
                         cloudAnimate.center = CGPointMake(100.0, 90.0);
                     }
                     completion:NULL];

    [UIView animateWithDuration:8.0
                          delay:0.0
                        options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction
                     animations:^{
                         cloudAnimate1.center = CGPointMake(100.0, 150.0);
                     }
                     completion:NULL];


}

代码执行我想要的东西,所以我很高兴,但如果该视图已打开并且您退出应用程序并重新进入该视图,那么云将停留在终点。我必须离开视图然后回到它,让它们重新开始。

有没有办法当你退出视图时,云会停留在它们所在的位置,当你回到它们的位置时,它们就像往常一样继续制作动画?

2 个答案:

答案 0 :(得分:1)

这是你的问题吗?

- (void)**viewDidAppear**:(BOOL)animated
{
    [super **viewDidLoad**];

答案 1 :(得分:0)

移动线

cloudAnimate.center = CGPointMake(400.0, 90.0);
cloudAnimate1.center = CGPointMake(400.0, 150.0);

进入viewWillAppear:。这样,每次重新打开应用程序时,按钮位置都会重置。