我移動我的UIImageView
與層周圍的屏幕。在某些時候,我試圖使用imageView.frame.origin.x
檢索移動的imageView的x和y座標,我接收到的原始座標不是移動後的新座標。如何正確獲取X和Y?UIImageView XY座標與層移動
這裏是我的代碼:
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];
你可以加入一段代碼嗎?你在調用setNeedsLayout還是layoutIfNeeded? – bryanmac
信息太少。如何發佈一些代碼? –
已發佈我的回覆對這段代碼是正確的。在UIImageView的中心設置一個動畫,而不是它的圖層位置。否則'框架'是未定義的。 – Tommy