Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS:为什么动画完成后对象会转到起始位置_Ios_Objective C_Animation_Uiviewanimation - Fatal编程技术网

iOS:为什么动画完成后对象会转到起始位置

iOS:为什么动画完成后对象会转到起始位置,ios,objective-c,animation,uiviewanimation,Ios,Objective C,Animation,Uiviewanimation,))我正在尝试按如下方式设置UIButton的动画(两个并行动画:更改图像和移动),动画按钮应移动后,但动画完成后,按钮将转到开始位置。请帮我修一下!提前谢谢 - (IBAction)bugOneTapped:(id)sender { [UIView animateWithDuration:1.0 animations:^{ self.bugOneButton.imageView.animationImages =

))我正在尝试按如下方式设置UIButton的动画(两个并行动画:更改图像和移动),动画按钮应移动后,但动画完成后,按钮将转到开始位置。请帮我修一下!提前谢谢

- (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);  
}

删除代码中的以下行

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

它将修复..

@Genie-Wanted说得对,删除代码

self.bugOneButton.center = CGPointMake(self.bugOnePositionX, self.bugOnePositionY)
这将重置按钮位置!

删除这两行

- (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];
                 }];


}

您再次将中心设置为完成块后的初始位置。删除此self.bugOnePositionY=self.bugOnePositionY-50;谢谢,但我已经改变了上面的Y位置,为什么它没有改变?也许,当你使用动画块时,开始动画和停止动画在这里是不必要的。我认为他正在使用任何第三方库来制作动画@geniewante我认为你使用了第三方库,那么动画时间比你的动画时间长,因此,当它完成时,将重置它。或方法停止设置动画