如何获得一个项目的坐标,而这是动画? [英] How to get a item's coordinates while it is animating?

查看:134
本文介绍了如何获得一个项目的坐标,而这是动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以动画在屏幕上的东西,像这样:

I can animate something across the screen like so:

aView.frame = CGRectMake(100,100,50,50); 
[UIView animateWithDuration:25.0 delay:0.0 options:UIViewAnimationCurveLinear animations:
     ^{ 
         aView.frame = CGRectMake(200,100,50,50);         
     } 
         completion:^(BOOL finished)
     {
         aView.hidden = YES; 
     }
 ];

..但我怎么获得该项目的位置,而这是动画?如果我把屏幕上的一个按钮,并使用这个动作。

..but how do I get the position of the item while it is animating? If I put a button on the screen and use this action

-(IBAction)buttonTapped:(id)sender
{
   NSLog(@"x pos:%f", aframe.origin.x)l
}

那么我从这个得到的是

then all I get from this is

x pos:200.00

..这是在最后的项目的位置,而不是当前。我如何获取当前?

..which is the final position of the item, but not the current. How do I get the current?

推荐答案

看看的CALayer 的<一个href=\"http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instm/CALayer/$p$psentationLayer\"相对=nofollow> presentationLayer 财产。它拥有被动画层的当前值。

Look at CALayer's presentationLayer property. It holds the current values of the layer being animated.

您将不得不进口的 QuartzCore 的框架。

You will have to import QuartzCore framework.

修改

具体做法是:

#import <QuartzCore/CALayer.h>
// ...
CGPoint inMotionPosition = myView.layer.presentationLayer.position;

这篇关于如何获得一个项目的坐标,而这是动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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