2

Is it possible to create a custom uiview (loaded from a nib) with bounds smaller than the frame. So I would like to show a part of the frame/view. On a button press I want to slide the bounds to the right to see the whole frame. Can this be done?

user517153
  • 205
  • 2
  • 8

4 Answers4

0

It definitely can, it's pretty much how the Sliding Views work under the hood.

Jordaan Mylonas
  • 1,261
  • 1
  • 11
  • 24
0

I think frame and bounds is directly linked to the main layer of the view... but you could add a sublayer and move that.

Bastian
  • 10,403
  • 1
  • 31
  • 40
0
  • Make the class a subview of UIView.
  • Put the content that you want to display in another view and attach it with -addSubview.
  • Make sure that the subview has UIAutoresizingNone set (or you set self.autoresizesSubviews = NO) and has bounds that correspond to its actual size.
  • Set self.clipsToBounds = YES.
  • Update the origin of the subview's frame to adjust which part of the subview is visible in the front view, or grow the bounds of the main view to show more of the clipped subview.
Seamus Campbell
  • 17,816
  • 3
  • 52
  • 60
0

A view's bounds represents the bounding rectangle in the view's own coordinate system. The frame is the bounding rectangle in the superview's coordinate system. By changing a view's transform, you could easily create a bounds rectangle with origin={0, 0} and size={1, 1}, even though the view's frame was origin={0, 0}, size={320, 480}. That view might cover the entire screen, but the bounds is still only 1 unit by 1 unit in size.

I see what you're trying to do, and that's really a different thing from bounds != frame. You're talking about having a content view that's only partially visible through an enclosing view. This is exactly what UIScrollView does for you.

Caleb
  • 124,013
  • 19
  • 183
  • 272