【问题标题】:Getting the actual origins of subviews iOS sdk获取子视图 iOS sdk 的实际来源
【发布时间】:2013-05-28 02:52:28
【问题描述】:

我有框架视图

_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 的较小版本)

【问题讨论】:

  • 我真的不知道你想在这里做什么。您当然可以使用:[anotherView setFrame:CGRectMake(x,y,width,height)]。但你已经知道了。所以请发布更多细节。
  • convertRect:toView:convertRect:fromView: 有什么问题?
  • 我的问题是,在你的情况下如何使用这些方法(convertRect:toView: 或 convertRect:fromView:)??

标签: objective-c frame


【解决方案1】:

您应该使用-(CGRect)convertRect:fromView:。例如:

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;

【讨论】:

  • 感谢回复...但它不起作用...我想转换子视图框架而不是其他视图框架,我想要子视图相对于“anotherView”的相对框架跨度>
猜你喜欢
  • 2013-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多