Thursday, May 31, 2012

iOS-- Managing Subviews


1. Adding Subviews

  •  insertSubview:atIndex:
  •  insertSubview:aboveSubview:
  •  insertSubview:belowSubview:



2. Reordering and Removing Subviews

  • Use [parentView exchangeSubviewAtIndex:i withSubviewAtIndex:j] to exchange the positions of two views.
  • Move subviews to the front or back using bringSubviewToFront: and 
  • sendSubviewToBack.
  • To remove a subview from its parent, call [childView removeFromSuperview]. If 
  • the child view had been onscreen, it disappears. Removing a child from the superview 
  • calls a release on the subview, allowing its memory to be freed if its retain
  • count has returned to 0.

3. View Callback

  •  didAddSubview: is sent to a view after a successful invocation of addSubview: lets subclasses of UIView perform additional actions when new views are added.
  • didMoveToSuperview: informs views that they’ve been re-parented to a new superview. The view may want to respond to that new parent in some way.When the view was removed from its superview, the new parent is nil.
  • willMoveToSuperview: is sent before the move occurs.
  • didMoveToWindow: provides the callback equivalent of didMoveToSuperview but when the view moves to a new Window hierarchy instead of to just a new superview.
  • willMoveToWindow: is, again, sent before the move occurs.
  • willRemoveSubview: informs the parent view that the child view is about to be removed.

No comments:

Post a Comment