开发者

Efficient method to find subviews outside of frame of view

开发者 https://www.devze.com 2023-03-15 07:01 出处:网络
I have an array of views that are also subviews of a base view. I want to efficiently remove all views开发者_如何学运维 that are not inside the frame of the base view (i.e. not visible).

I have an array of views that are also subviews of a base view. I want to efficiently remove all views开发者_如何学运维 that are not inside the frame of the base view (i.e. not visible).

I'm looking for suggestions to find the most efficient method besides of computing the intersection of all frames with the base view frame.


If you want to remove your subviews when they are not inside the base view's frame, you will need to calculate their frames intersections with the base view. Alternatively, you could use bool CGRectContainsRect ( CGRect rect1, CGRect rect2 ); instead of fully calculating the intersection.

If you are trying to do this to optimize subview drawing, you can think of using the UIView'scliptobounds property, instead of removing the subviews:

clipsToBounds

A Boolean value that determines whether subviews are confined to the bounds of the receiver.

@property(nonatomic) BOOL clipsToBounds

Discussion

Setting this value to YES causes subviews to be clipped to the bounds of the receiver. If set to NO, subviews whose frames extend beyond the visible bounds of the receiver are not clipped. The default value is NO.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号