iPhone/iOS: Will there be called any method if a UIView is added as a subview

前端 未结 4 1655
情话喂你
情话喂你 2021-01-11 10:23

If I add a view as a subview like so

[self.view addSubview:mySubview];

Will there be called any method on mySubview, that I could override

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-11 11:06

    Yes, There is a method which get called if one change the superview . you need to override the below method in your subview class.

    - (void)willMoveToSuperview:(UIView *)newSuperview
    - (void)didMoveToSuperview
    

    From UIView Doucumentation

    willMoveToSuperview:, didMoveToSuperview—Implement these methods as needed to track the movement of the current view in your view hierarchy.

提交回复
热议问题