如何创建多阶段 UIImageView 动画?

2024-04-15移动开发问题
7

本文介绍了如何创建多阶段 UIImageView 动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试制作多阶段动画,以便 UIImageView (1) 淡入,(2) 移动,(3) 滑出屏幕.

I'm trying to do a multistage animation, so that a UIImageView (1) fades in, (2) moves, (3) slide off the screen.

似乎只有第 1 阶段有效.我究竟做错了什么?代码如下:

Only stage 1 seems to work. What am I doing wrong? Here's the code:

// FIRST PART - FADE IN
-(void)firstAnim
{
    // 'sprite' is a UIImageView
    [sprite setAlpha:0.1f];
    [UIView beginAnimations:@"anim1" context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:0.25];
    [UIView setAnimationDidStopSelector:@selector(secondAnim)];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [sprite setAlpha:1.0f];
    [UIView commitAnimations];
}


// SECOND PART - MOVE
-(void)secondAnim
{
    [UIView beginAnimations:@"anim2" context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDidStopSelector:@selector(thirdAnim)];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    sprite.frame = CGRectMake(170, 184, 20, 20);
    [UIView commitAnimations];
}

// THIRD PART - SLIDE OFF SCREEN
-(void)thirdAnim
{   
    [UIView beginAnimations:@"anim3" context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    sprite.frame = CGRectMake(170, 420, 20, 20);
    [UIView commitAnimations];
}

推荐答案

你需要添加一个调用来设置自己为动画代理:

You need to add a call to set yourself as the animation delegate:

[UIView setAnimationDelegate:self];

最好在最后一个动画块中将自己取消设置为代理(设置为 nil).

It would be a good idea to unset yourself as the delegate (set to nil) in the last animation block.

这篇关于如何创建多阶段 UIImageView 动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7