我的 UIView 动画有什么问题?
What is wrong with my UIView Animation?
我正在尝试通过 3 个步骤创建动画。第一步应该在放大的图片上向右移动一点。第二步是在 3 秒内将效果放大到其他图片。最后一步是在 3 秒内再次缩小不同的图片。我完全按照我的意愿执行了前两个步骤,但是当我添加 3. 步骤时出了点问题。就像它试图同时执行 2. 和 3. 步骤一样。请帮我。这是我的代码。
imgAnimationBase.image = [UIImage imageNamed:@"animation-1.jpg"];
imgAnimationBase.alpha = 1.0;
imgAnimationBase.transform =CGAffineTransformMakeScale(1.5,1.5);
imgAnimationBase.frame=CGRectMake(20, imgAnimationBase.frame.origin.y, imgAnimationBase.frame.size.width, imgAnimationBase.frame.size.height);
[UIView transitionWithView:imgAnimationBase
duration:3.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
imgAnimationBase.frame=CGRectMake(-110, imgAnimationBase.frame.origin.y, imgAnimationBase.frame.size.width, imgAnimationBase.frame.size.height);
}
completion:^(BOOL finished) {
imgAnimationBase.transform =CGAffineTransformMakeScale(1,1);
imgAnimationBase.frame=CGRectMake(10, imgAnimationBase.frame.origin.y, imgAnimationBase.frame.size.width, imgAnimationBase.frame.size.height);
[UIView transitionWithView:imgAnimationBase
duration:3.0f
options:NO
animations:^{
imgAnimationBase.image = [UIImage imageNamed:@"animation-2.jpg"];
[UIView animateWithDuration:3.0 animations:^{
imgAnimationBase.alpha = 1.0;
imgAnimationBase.transform =CGAffineTransformMakeScale(2,2);
}];
}
completion:^(BOOL finished) {
[UIView transitionWithView:imgAnimationBase
duration:3.0f
options:NO
animations:^{
imgAnimationBase.image = [UIImage imageNamed:@"animation-3.jpg"];
[UIView animateWithDuration:3.0 animations:^{
imgAnimationBase.alpha = 1.0;
imgAnimationBase.transform =CGAffineTransformMakeScale(1,1);
}];
}
completion:^(BOOL finished) {
}];
}];
}];
如评论中所述 - 当您已经在 animations
块中时,无需第二次调用 [UIView animateWithDuration: animations:]
。
我正在尝试通过 3 个步骤创建动画。第一步应该在放大的图片上向右移动一点。第二步是在 3 秒内将效果放大到其他图片。最后一步是在 3 秒内再次缩小不同的图片。我完全按照我的意愿执行了前两个步骤,但是当我添加 3. 步骤时出了点问题。就像它试图同时执行 2. 和 3. 步骤一样。请帮我。这是我的代码。
imgAnimationBase.image = [UIImage imageNamed:@"animation-1.jpg"];
imgAnimationBase.alpha = 1.0;
imgAnimationBase.transform =CGAffineTransformMakeScale(1.5,1.5);
imgAnimationBase.frame=CGRectMake(20, imgAnimationBase.frame.origin.y, imgAnimationBase.frame.size.width, imgAnimationBase.frame.size.height);
[UIView transitionWithView:imgAnimationBase
duration:3.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
imgAnimationBase.frame=CGRectMake(-110, imgAnimationBase.frame.origin.y, imgAnimationBase.frame.size.width, imgAnimationBase.frame.size.height);
}
completion:^(BOOL finished) {
imgAnimationBase.transform =CGAffineTransformMakeScale(1,1);
imgAnimationBase.frame=CGRectMake(10, imgAnimationBase.frame.origin.y, imgAnimationBase.frame.size.width, imgAnimationBase.frame.size.height);
[UIView transitionWithView:imgAnimationBase
duration:3.0f
options:NO
animations:^{
imgAnimationBase.image = [UIImage imageNamed:@"animation-2.jpg"];
[UIView animateWithDuration:3.0 animations:^{
imgAnimationBase.alpha = 1.0;
imgAnimationBase.transform =CGAffineTransformMakeScale(2,2);
}];
}
completion:^(BOOL finished) {
[UIView transitionWithView:imgAnimationBase
duration:3.0f
options:NO
animations:^{
imgAnimationBase.image = [UIImage imageNamed:@"animation-3.jpg"];
[UIView animateWithDuration:3.0 animations:^{
imgAnimationBase.alpha = 1.0;
imgAnimationBase.transform =CGAffineTransformMakeScale(1,1);
}];
}
completion:^(BOOL finished) {
}];
}];
}];
如评论中所述 - 当您已经在 animations
块中时,无需第二次调用 [UIView animateWithDuration: animations:]
。