【发布时间】:2023-03-03 21:42:01
【问题描述】:
我正在尝试查找在屏幕上显示动画的 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 的当前位置?
【问题讨论】:
标签: iphone objective-c ios animation cgpoint