我正在使用SnowFall应用程序,其中图像从屏幕顶部下降到底部.这个应用程序使用动画来完成这项任务.
//把片放在我们的主视图中[self.view addSubview:flakeView];
[UIView beginAnimations:nil context:flakeView];
// set up how fast the flake will fall
[UIView setAnimationDuration:4 * speed];
// set the postion where flake will move to
//flakeView.frame = CGRectMake(endX, 500.0, 25.0 * scale, 25.0 * scale);
flakeView.frame = CGRectMake(endX, 500.0,16, 16);
// set a stop callback so we can cleanup the flake when it reaches the
// end of its animation
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
我的问题是我需要捕捉它们移动的图像帧.
有什么办法可以让我找到屏幕上图像的当前位置.
谢谢
编辑:我正在尝试使用:CGRectIntersectsRect(frame1,frame2)其中frame1是动画的图像,frame2是一个对象.如果图像与物体相交,我必须要做一些事情.
当您应用这样的动画时,视图的框架(以及视图的CALayer框架)会立即反映最终位置.
要在动画期间获取当前位置的帧,您需要视图的图层presentationLayer.
CALayer *layer = flakeView.layer.presentationLayer;
CGRect layerFrame = layer.frame;
BOOL intersects = CGRectIntersectsRect(layerFrame, frame2);
Run Code Online (Sandbox Code Playgroud)