iosuiviewuiviewcontrollerviewdidloadviewdidappear

Is there any viewDidAppear method for UIView (not UIViewController)?


I need to understand when UIView appears on the screen, so I need an analogue of the viewDidAppear method.

I found a UIView lifecycle:

  1. willMoveToSuperview
  2. invalidateIntrinsicContentSize
  3. didMoveToSuperview
  4. awakeFromNib
  5. willMoveToWindow
  6. needsUpdateConstraints
  7. didMoveToWindow
  8. setNeedsLayout
  9. updateConstraints
  10. layoutSubviews
  11. drawRect

I tried all of these methods, but I didn't get an answer.


Solution

  • No there is no viewDidAppear in UIView. you may override func drawRect to do any UI changes that you need on UIView inherited View.

    SideNote - In case you want get drawrect to update at later times, Call setNeedsDisplay. setNeedsDisplaywill not immediately call drawRect but marks the receiver’s entire bounds rectangle as needing to be redrawn.

    In other words - You should never call drawRect yourself. Instead, you tell the system that drawing needs to be done by using the setNeedsDisplay method, which marks the view as dirty. And the drawRect method of the subclass would then be called during the next update cycle.

    As per the queries from OP(@Alexander), he just need to set some variable so it advisable to use any of the following override functions, depending on action need to be performed