Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIImageView XY坐标与图层移动_Iphone_Objective C_Coordinates_Layer - Fatal编程技术网

Iphone UIImageView XY坐标与图层移动

Iphone UIImageView XY坐标与图层移动,iphone,objective-c,coordinates,layer,Iphone,Objective C,Coordinates,Layer,我在屏幕周围移动带有图层的UIImageView。在某个时刻,我尝试使用imageView.frame.origin.x检索移动的imageView的x和y坐标时,我收到的是原始坐标,而不是移动后的新坐标。如何正确获取X和Y 这是我的密码: UIImageView *imageView = [[UIImageView alloc] initWithFrame:rect]; imageView.animationImages = [NSArray arrayWithArray:imgName

我在屏幕周围移动带有图层的
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];
根据
帧的属性:

警告:如果转换属性不是标识转换,则 此属性的值未定义,因此应忽略

如果调整视图层的
变换
仿射变换
属性(UIView在设置变换时实际会更改这些属性),则
属性也将变得未定义。在Cocoa Touch中,在合成器合成时应用变换。目前,当应用变换时,您似乎得到的是原始帧,就好像没有变换一样,但正如文档所说,它是未定义的,所以不要依赖于此


如果只是在不进行其他变换的情况下移动视图,我建议您使用视图的
center
属性,而不是应用变换。这将正确更新您的帧。基于经验证据,UIKit似乎也足够聪明,与应用转换相比,仅仅调整中心不会有任何性能下降。

您可以包含一个代码片段吗?您是呼叫setNeedsLayout还是LayoutIfNeed?信息太少。发布一些代码怎么样?我已经发布的答案对于这个代码是正确的。在UIImageView的中心而不是图层位置设置动画。否则,
frame
未定义。我必须使用layer,因为我的路径非常复杂。那么您是否尝试读回
layer.position
属性?这应该是正确的动画后。甚至完全放弃frame属性也是值得的-首先设置视图,使其具有正确的大小并处于(0,0),然后通过layer.position执行其余操作。是的,我最近尝试了all-layer.frame,layer.bounds和layer.position-所有东西都指向原始位置如果检查layer.transform,会得到什么?例如,layer.transform.m11是1.0;然后所有其他的大部分都是0.0和一些1.0