了解UIAnimation [英] Understanding of UIAnimation

查看:86
本文介绍了了解UIAnimation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码执行一些动画

I am trying to use following code to perform few animations

-(void) performSlidingfromX:(int) xx fromY:(int) yy 
{
UIImageView *Image= [self getImage];

[UIView beginAnimations:nil context:NULL];  
[UIView setAnimationDuration: 1.0];
[UIView setAnimationBeginsFromCurrentState:true];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
[token setFrame:CGRectMake(xx, yy, 64, 64)];
[UIView commitAnimations];

}

我正在调用for for循环

and i am calling like it in for loop

for (i = 0; i < totMoves; i++) {
    Moment *m = [moments objectAtIndex:i];
    int xx= [m X];
    int yy= [m Y];

    [self performSlidingfromX:xx fromY:yy];

}

我面临的问题是它的最终动画位置,例如,如果我为xx输入以下时刻,yy

The problem that i am facing is that its animating to final position, for example , If i input the following moments for xx,yy

0,0
50,0
50,50

它将图像从0,0移动到50,50对角线,I希望它首先滑动到垂直,然后垂直滑动。

It moves the image from 0,0 to 50,50 diagonally, I want it to slide to horizantly first and then vertical.

任何帮助?

谢谢

推荐答案

使用新的块动画。它简单而稳定:

use new block animations. it is easy and stable:

[UIView animateWithDuration:0.5 
                          delay:0 
                        options:UIViewAnimationOptionBeginFromCurrentState
                     animations:^{
                         [token setFrame:CGRectMake(xx, 0, 64, 64)];
                         //here you may add any othe actions, but notice, that ALL of them will do in SINGLE step. so, we setting ONLY xx coordinate to move it horizantly first.
                     } 
                     completion:^(BOOL finished){

                         //here any actions, thet must be done AFTER 1st animation is finished. If you whant to loop animations, call your function here.
                         [UIView animateWithDuration:0.5 
                                               delay:0 
                                             options:UIViewAnimationOptionBeginFromCurrentState 
                                          animations:^{[token setFrame:CGRectMake(xx, yy, 64, 64)];} // adding yy coordinate to move it verticaly} 
                                          completion:nil];
                     }];

这篇关于了解UIAnimation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆