iphone - 在动画期间访问 UIView 的当前位置

标签 iphone objective-c ios animation cgpoint

我试图找到在屏幕上动画的 iPhone ImageView 的当前位置。

我像这样创建 imageView 并设置动画

-(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];
                     }
     ];
}

然后为了检测 imageView 的当前 CGPoint,我每 60 秒调用一次此方法

-(void)findPoint{

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

然而,这只给我动画结束的点,我想获得在屏幕上动画的图像的当前 CGPoint。除了 UIViewAnimationOptionAllowUserInteraction 之外,我还需要应用其他选项来执行此操作吗?如果不是,我如何获取动画 imageView 的当前位置?

最佳答案

您可以使用 presentationLayer - CALayer 的一个属性,它“提供与当前显示的图层版本的近似值”。像这样使用它:

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

关于iphone - 在动画期间访问 UIView 的当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7624755/

相关文章:

objective-c - 一对多核心数据绑定(bind)问题

ios - 在 Web View 中生成 PDF 时,如何先将 PDF 数据写入文件

iphone - 我们可以将属性/合成到 sqlite3 * 数据库对象吗?

iphone - 在 Objective-C 中获取下周六的日期?

iphone - float 问题

ios - ip camera feed 到 IOS 应用程序如何允许全局连接?

iphone - 更改导航 Controller 工具栏的色调

objective-c - 如何动态填充 NSOutlineView 的列?

ios - SocketRocket 在 connectionDidFinishLoading 后崩溃

ios - 了解崩溃日志