【发布时间】:2011-08-30 22:11:15
【问题描述】:
我在屏幕周围移动我的UIImageView。当我尝试使用imageView.frame.origin.x 检索移动后的 imageView 的 x 和 y 坐标时,我收到的是原始坐标,而不是移动后的新坐标。如何正确获取 X 和 Y?
这是我的代码:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:rect];
imageView.animationImages = [NSArray arrayWithArray:imgNameArr];
imageView.animationDuration = 2;
imageView.animationRepeatCount = 0;
[imageView startAnimating];
[self.view addSubview:imageView];
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.duration = speed;
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
CGMutablePathRef pointPath = CGPathCreateMutable();
CGPathMoveToPoint(pointPath, NULL, rect.origin.x, rect.origin.y);
CGPathAddLineToPoint(pointPath, NULL, x, y);
pathAnimation.path = pointPath;
CGPathRelease(pointPath);
[imageView.layer addAnimation:pathAnimation forKey:[NSString stringWithFormat:@"pathAnimation%@",objId]];
[imageView release];
【问题讨论】:
-
你能包含一个代码sn-p吗?你是在调用 setNeedsLayout 还是 layoutIfNeeded?
-
信息太少。发布一些代码怎么样?
-
我已经发布的答案对于此代码是正确的。在 UIImageView 的中心而不是图层的位置上设置动画。否则
frame未定义。
标签: iphone objective-c coordinates layer