在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。
- animationUICollectionView contentOffset不显示不可见的单元格
- 在键盘上同步animation键盘将同时显示键盘和硬件键盘和虚拟键盘
- 如何使溶解animation在iPhone上更改视图?
- 使用贝塞尔path作为剪贴蒙版
- 核心animation中的圆形箭头蒙版的长度的animation
- 我怎么能animation的UIViewController推UINavigationBar背景更改?
- 用OpenGL ES结合核心animation
- iOS布局animation在GMSMapView拖动时忽略持续时间
- Swift 2 – performBatchUpdates – 在UICollectionView框架内部可视化的时候,一个接一个地animation单元格