iOS didMoveToSuperview
2015-10-08 17:08
1581 查看
iOS UIView 类目 UIViewHierarchy
有一个方法
didMoveToSuperview
官方解释如下
Tells the view that its superview changed.
大致意思: 当view的父级视图更改的时候会调用此方法
The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the superview changes.
大致意思:此方法默认实现,不做任何操作。子视图可以实现此方法,添加自己所需要的功能
通过以上我们可以理解为 次方法在view被添加新的父级视图的时候会调用。
我们尝试测试一下
首先新建一个项目TestDidMoveToSuperview
新建一个View 继承UIView 起名:MyTestView
接下来我们在ViewController.m中添加view
运行 是不是看到 log了
好了 。大家有什么问题欢迎继续讨论
苹果开发群2 :492222303 欢迎加入 欢迎讨论问题
有一个方法
didMoveToSuperview
官方解释如下
Tells the view that its superview changed.
大致意思: 当view的父级视图更改的时候会调用此方法
The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the superview changes.
大致意思:此方法默认实现,不做任何操作。子视图可以实现此方法,添加自己所需要的功能
通过以上我们可以理解为 次方法在view被添加新的父级视图的时候会调用。
我们尝试测试一下
首先新建一个项目TestDidMoveToSuperview
新建一个View 继承UIView 起名:MyTestView
</pre><p></p></blockquote><p></p><p class="p1">实现方法</p><p class="p1"></p><pre name="code" class="objc">-(void)didMoveToSuperview{ NSLog(@"test didMoveToSuperview"); }
接下来我们在ViewController.m中添加view
#import "ViewController.h" #import "MyTestView.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. MyTestView *testView=[[MyTestView alloc]initWithFrame:CGRectMake(10, 120, 300, 300)]; testView.backgroundColor=[UIColor grayColor]; [self.view addSubview:testView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
运行 是不是看到 log了
好了 。大家有什么问题欢迎继续讨论
苹果开发群2 :492222303 欢迎加入 欢迎讨论问题
相关文章推荐
- CALayer与UIView的关系
- UIView的bounds和frame区别
- uiview
- uiview生命周期
- UIView翻译 (参考)
- iOS 转变UIView到UIImage
- UIView动画
- initWithFrame 和 initWithCoder
- [CS193P] 第六堂課摘要及心得筆記
- UI第一天
- 棋盘
- ios实现button变换颜色并可以放大、缩小、旋转
- uiview contentViewmode
- iphone开发小记 基础知识2
- iphone开发小记 基础知识3
- [笔记]I 群聊天记录2012/03/中
- iPhone开发进阶(2) --- iPhone应用程序/项目的构成
- 视图弹出后放大又缩小的动画实现、类似于alertView效果
- iPhone SDK开发:自定义UIAlertView
- IOS开发中的UIScreen、UIView、UIWindow和UIViewController