关于  - (void)removeFromSuperview  

苹果官网API中是这么描述的:

Unlinks the view from its superview and its window, and removes it from the responder chain.

译:把当前视图从它的父视图和窗口中移除,同时也会把它从响应事件操作的响应者链中移除。

说明一下几点:

1、执行removeFromSuperview方法,只是该视图不在屏幕中显示,并没有将该视图从内存中移除。所以我们如果需要使用该视图,不需要再次创建,而是直接addSubview就可以了。(若视图使用了懒加载,仅仅使用了removeFromSuperview,再次调用self.view时,不会执行懒加载方法的);

2、若要彻底移除视图,我们需要2步:removeFromSuperview 然后 置为nil;

3、无论是ARC还是MRC中多次调用removeFromSuperviewaddSubview:方法,都不会造成造成重复释放和添加。

4、苹果的官方API注明:Never call this method from inside your view’s drawRect: method.

译:永远不要在你的ViewdrawRect:方法中调用removeFromSuperview

 

转载请注明:

http://www.jianshu.com/p/b817c94cac0b

相关文章:

  • 2021-10-06
  • 2021-06-02
  • 2022-01-19
  • 2021-05-30
  • 2022-01-06
  • 2021-12-09
  • 2021-12-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2022-01-13
  • 2021-12-05
  • 2021-05-27
  • 2022-03-07
相关资源
相似解决方案