视图控制

it2024-10-30  15

1、常用属性

self.view;

self.navigationController;//自动赋值

self.navigationItem;//手动赋值

self.tabBarController;//自动赋值

self.tabBarItem;//手动赋值

 

  1,可视化属性

    UIView * v1;

    UIView * v2;

    v1.backgroundColor;

    

    v1.subviews;

    

    2,视图层次

    [self.view addSubview:v1];

    [self.view addSubview:v2];

    [v1 removeFromSuperview];

    self.view.subviews;

    

    [self.view bringSubviewToFront:v1]; //将视图v1显示在前面

    [self.view sendSubviewToBack:v1]; //将视图V1显示在后面

    [self.view insertSubview:v2 atIndex:0]; //将v2插入在view的0的位置(最底层为0)

 

3,视图过度动画

    UIScrollView * s = [[UIScrollView alloc]initWithFrame:self.view.bounds];

    [self.view addSubview:s];

    

    UIImageView * imageV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"123.png"]];

    

    s.contentSize = imageV.frame.size;

    

    [s addSubview:imageV];

    

    //偏移量

    s.contentOffset;

 

    UIWebView

    UIWebView * w = [[UIWebView alloc]initWithFrame:self.view.bounds];

    [self.view addSubview:w];

    

    NSURL * url = [NSURL URLWithString:@"http://www.taobao.com"];

    NSURLRequest * r = [NSURLRequest requestWithURL:url];

    [w loadRequest:r];

 

 

//2,初始化方法

1.代码初始化

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    //入,该视图控制器类和storyboard中某个可视化控制器绑定,该方法不会运行。

}

2.storyboard初始化

-(void)awakeFromNib

{

    //通过纯代码创建一个视图控制器对象,该方法不会走。

}

 

3,加载根视图

-(void)loadView

{

    //此方法,只做一件事

    //为self.view属性赋值

}

 

 

视图切换时间点

 

-(void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    

    

}

-(void)viewDidAppear:(BOOL)animated

{

    [super viewDidAppear:animated];

}

 

-(void)viewWillDisappear:(BOOL)animated

{

    [super viewWillDisappear:animated];

    

    

}

-(void)viewDidDisappear:(BOOL)animated

{

    [super viewDidDisappear:animated];

    

    

}

 

清除临时数据

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

    

    

}

 

转载于:https://www.cnblogs.com/ylg-----/p/4755655.html

最新回复(0)