UIView隐藏儿童视图超出界限(UIView hide children views when out of bounds)

我有一个看法,说100x100。 它有一组uiviews作为子视图:让说30x30

如果子视图具有左上角的坐标:(90,90) - 我希望看到这个子视图的一部分。 但我仍然看到整个地区 - 即使是超出了父母的境界

问题是如何使uiview只显示那些属于原始界限的子视图的那些部分?

谢谢

I have a view, lets say 100x100. And it has set of uiviews as subviews: let say 30x30

If a subview has top-left coordinate: (90,90) - I expect to see only part of this subview. But I still see entire area - even if it is out of parents bounds

The question is how to make uiview to show only those parts of subview, which are in original bounds?

thank you

最满意答案

将视图的clipsToBounds属性设置为YES 。

以编程方式: view.clipsToBounds=YES;

通过界面构建​​器: Click the view->Attributes Inspector->Check Clip subviews

Set view's clipsToBounds property to YES.

Programmatically: view.clipsToBounds=YES;

Through interface builder: Click the view->Attributes Inspector->Check Clip subviews

UIView隐藏儿童视图超出界限(UIView hide children views when out of bounds)

我有一个看法,说100x100。 它有一组uiviews作为子视图:让说30x30

如果子视图具有左上角的坐标:(90,90) - 我希望看到这个子视图的一部分。 但我仍然看到整个地区 - 即使是超出了父母的境界

问题是如何使uiview只显示那些属于原始界限的子视图的那些部分?

谢谢

I have a view, lets say 100x100. And it has set of uiviews as subviews: let say 30x30

If a subview has top-left coordinate: (90,90) - I expect to see only part of this subview. But I still see entire area - even if it is out of parents bounds

The question is how to make uiview to show only those parts of subview, which are in original bounds?

thank you

最满意答案

将视图的clipsToBounds属性设置为YES 。

以编程方式: view.clipsToBounds=YES;

通过界面构建​​器: Click the view->Attributes Inspector->Check Clip subviews

Set view's clipsToBounds property to YES.

Programmatically: view.clipsToBounds=YES;

Through interface builder: Click the view->Attributes Inspector->Check Clip subviews