TL;博士:的frame
是假的,当你有一个非身份transform
。改为改变center
。
从the documentation:
警告如果transform
属性不是恒等变换,这个属性的值是不确定的,因此应被忽略。
当您在第一行设置转换,然后在未定义之后读取帧时,您实际返回的是什么。
// Setting a non-identity transform (1)
myImageView.transform = CGAffineTransformMakeRotation(45);
CGRect frame = myImageView.frame; // At this point the frame is undefined (2)
// You are modifying something which is undefined from now on ...
此外,您不仅应该阅读框架,因为它是未定义的,您也不应该设置它。
如果transform
属性包含非标识转换,frame属性的值是未定义的并且不应该修改。
解决这个问题来的文件
在这种情况下的下一句话,你可以重新使用中心属性查看和调整使用bounds属性,而不是规模。
由于您只是改变位置,我建议您不要触摸框架,而是读取图像视图的center
并将其设置为新的值。与框架相同,center
不受转换的影响。
CGPoint center = myImageView.center;
center.x = x_center_position; // Note that the `center` is not the same as the frame origin.
center.y = y_center_position; // Note that the `center` is not the same as the frame origin.
myImageView.center = center;
非常感谢您的大力帮助。 – 2013-03-02 19:26:17