2013-03-02 22 views
1

我使用下面的代码,以旋转和变换的图像视图挤压:图像狭窄,当我申请的旋转和变换

myImageView.transform = CGAffineTransformMakeRotation(45); // rotation 

CGRect frame = myImageView.frame; 
frame.origin.x = x_position; 
frame.origin.y = y_position; 
myImageView.frame = frame; // transformation 

回答

2

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; 
+0

非常感谢您的大力帮助。 – 2013-03-02 19:26:17

0

尝试删除的ImageView

的自动调整面膜
imageView.autoresizingMask = UIViewAutoresizingNone; 

这可能会解决你的问题