0

我有框架视图

_SceneImageView.frame = CGRectMake(20, 95, 984, 558);

我用框架向这个 _SceneImageView 添加了一个子视图

subview.frame = CGRectMake(325, 220, 200, 200);

现在我想将该子视图添加到另一个带有框架的视图

anotherView.frame = CGRectMake(450, 110, 512, 405);

如何将子视图的矩形从大视图转换为小视图???

有两个图像视图,_SceneImageView.frame = CGRectMake(20, 95, 984, 558); 和 otherView.frame = CGRectMake(450, 110, 512, 405);

我将一个子视图添加到_SceneImageView,现在我想将子视图的矩形转换为“anotherView”(anotherView 是_SceneImageView 的较小版本)

4

1 回答 1

1

You should use -(CGRect)convertRect:fromView:. For example:

CGRect subFrame;
CGRect sceneFrame;

// root frame
_SceneImageView.frame = CGRectMake(20, 95, 984, 558);

// sub frame
subview.frame         = CGRectMake(325, 220, 200, 200);

// frame with coordinates from root view
sceneFrame        = CGRectMake(450, 110, 512, 405);

// convert coordinates from root view to coordinates for subview
subFrame          = [subview convertRect:sceneFrame fromView:_SceneImageView];

anotherView.frame = subFrame;
于 2013-05-27T18:52:28.937 回答