在animation中访问UIView的当前位置

我正试图find在屏幕上animation的iPhone ImageView的当前位置。

我创build和animationimageView像这样

-(IBAction)button:(UIButton *)sender{ UIImageView *myImageView =[[UIImageView alloc] initWithImage: [UIImage imageNamed:@"ball.png"]]; myImageView.frame = CGRectMake(0, self.view.frame.size.height/2, 40, 40); [self.view addSubview:myImageView]; [myArray addObject:myImageView]; [UIView animateWithDuration:.5 delay:0 options:(UIViewAnimationOptionAllowUserInteraction) // | something here?) animations:^{ myImageView.frame = CGRectOffset(myImageView.frame, 500, 0); } completion:^(BOOL finished){ [myArray removeObject:myImageView]; [myImageView removeFromSuperview]; [myImageView release]; } ]; } 

然后检测当前的CGImageView我称这个方法每60秒

 -(void)findPoint{ for (UIImageView *projectile in bullets) { label.text = [NSString stringWithFormat:@"%f", projectile.center.x]; label2.text = [NSString stringWithFormat:@"%f", projectile.center.y]; } } 

然而,这只能给我animation结束的地方,我想要获得在屏幕上animation的图像的当前CGPoint。 有没有一个选项,我需要申请以外的UIViewAnimationOptionAllowUserInteraction做到这一点? 如果不是,我怎么得到一个animationimageView的当前位置?

您可以使用presentationLayer – CALayer的“提供与当前正在显示的图层的版本相近似的近似值”的属性。 就像这样使用它:

 CGRect projectileFrame = [[projectile.layer presentationLayer] frame]; 

这个答案中概述了更容易为view.frame设置KVO。 你可以检查新的值来获得新的框架作为CGRect。