4

I noticed that I can place subview outside of superview's bound (either partly or fully).
I wonder if that's acceptable, since it seems to be abnormal in usual iphone view programming.

Thank you.

Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
eugene
  • 39,839
  • 68
  • 255
  • 489

2 Answers2

8

This is acceptable and sometimes even common practice - custom implementations of scroll views or other "composite" views, for example, commonly place or move objects outside the superview's bounds.

You may be interested in the UIView property clipsToBounds, which restricts subview drawing to only the bounds of the superview.

Tim
  • 59,527
  • 19
  • 156
  • 165
  • 16
    It appears to me that user interaction is only possible for subviews that are inside their parents' bounds, or at least for those parts of the subviews that are inside their parents' bounds. If I add a UIBtton as a subview outside of the parent's bounds, I cannot click it. – iter Jul 07 '11 at 21:58
  • this comment is pure gold. i was getting mad over this "bug". – Alexander Theißen Jan 31 '12 at 17:07
1

Also note that out of bounds sub views pose a problem when implementing accessibility.

The accessibility frame gets displayed alright, but only appears when selecting an area of te said frame when touching inside the parent's bounds. If the sub view is completely outside the parent's bounds it is only accessible by side swiping with VoiceOver on. Touch dragging across the screen will only select a view when hiting said sub view within the parent's bounds.

Jeroen Leenarts
  • 502
  • 4
  • 11