2014-02-18 32 views
-2

))我想动画UIButton(两个并行动画:改变图像和移动),如下所示,动画按钮应该移动后,但在完成动画按钮后转向开始位置。请帮助解决它!提前致谢!iOS:为什么对象在动画合成之后转到开始位置

- (IBAction)bugOneTapped:(id)sender 
{ 
    [UIView animateWithDuration:1.0 
       animations:^{ 
        self.bugOneButton.imageView.animationImages = 
        [NSArray arrayWithObjects:[UIImage imageNamed:@"bugOne3"],[UIImage imageNamed:@"bugOne2"],[UIImage imageNamed:@"bugOne1"],[UIImage imageNamed:@"bugOne2"],[UIImage imageNamed:@"bugOne3"],[UIImage imageNamed:@"bugOne4"],[UIImage imageNamed:@"bugOne5"],[UIImage imageNamed:@"bugOne4"],nil]; 
        self.bugOneButton.imageView.animationDuration = 0.3; 
        [self.bugOneButton.imageView startAnimating]; 


        self.bugOneButton.center = CGPointMake(self.bugOnePositionX, self.bugOneButton.center.y - 50); 
        self.bugOnePositionY = self.bugOnePositionY - 50; 


       }completion:^(BOOL finished) { 
        [self.bugOneButton.imageView stopAnimating]; 
       }]; 

self.bugOneButton.center = CGPointMake(self.bugOnePositionX, self.bugOnePositionY); 
} 
+2

你又再次设置中心到完成块.. – GenieWanted

+0

删除此self.bugOnePositionY后的初始位置= self.bugOnePositionY - 50; – codercat

+0

谢谢,但我已经改变了上面的Y位置,为什么没有改变? – Romchas

回答

0

在你的代码删除以下行

self.bugOneButton.center = CGPointMake(self.bugOnePositionX, self.bugOnePositionY); 

它将修正..

+0

不))它不工作! – Romchas

0

@Genie诚征说的很对,删除代码

self.bugOneButton.center = CGPointMake(self.bugOnePositionX, self.bugOnePositionY) 

这将重置按钮位置!

+0

不))它不工作! – Romchas

+0

我认为你使用的是第三方库,那么动画的时间比你的动画的时间长,所以当它完成时,会重置它。或者方法stopAnimating导致 – fredZhu

0

re移动此两个线路

- (IBAction)bugOneTapped:(id)sender 
{ 
    [UIView animateWithDuration:1.0 
       animations:^{ 
        self.bugOneButton.imageView.animationImages = 
        [NSArray arrayWithObjects:[UIImage imageNamed:@"bugOne3"],[UIImage imageNamed:@"bugOne2"],[UIImage imageNamed:@"bugOne1"],[UIImage imageNamed:@"bugOne2"],[UIImage imageNamed:@"bugOne3"],[UIImage imageNamed:@"bugOne4"],[UIImage imageNamed:@"bugOne5"],[UIImage imageNamed:@"bugOne4"],nil]; 
        self.bugOneButton.imageView.animationDuration = 0.3; 
        [self.bugOneButton.imageView startAnimating]; 

        self.bugOneButton.center = CGPointMake(self.bugOnePositionX, self.bugOneButton.center.y - 50); 

       }completion:^(BOOL finished) { 
        [self.bugOneButton.imageView stopAnimating]; 
       }]; 


} 
+0

也许,当你使用AnimationBlocks时startAnimating和stopAnimating不是必要的 – GenieWanted

+0

我认为他使用任何第三方库制作动画@GenieWanted – codercat

+0

谢谢,但它也不起作用((( – Romchas

相关问题