iOS UI 02 UIimageview 和模态切换

来源:互联网 发布:ubuntu语言设置成中文 编辑:程序博客网 时间:2024/05/12 06:10

注意这是哪一个文件!!!RootViewController.m 

//  RootViewController.m

//  Ui03  - UIimageView

//

//  Created by dllo on 15/11/10.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import "RootViewController.h"

#import "RootView.h"

#import "SecondViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController


//ViewController的初始化方法

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

//{

//    self = [super initWithNibName: bundle:];

//    if (self) {

//

//    }

//    return self;

//}


- (void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    NSLog(@"nihao");

}

- (void)viewDidLoad {

    [superviewDidLoad];

    self.view.backgroundColor = [UIColorwhiteColor];

    RootView *rootV = [[RootViewalloc]initWithFrame:[[UIScreenmainScreen] bounds] ];

    [self.viewaddSubview:rootV];

    [rootV release];

    

    

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];

    button.frame = CGRectMake(150, 150, 150, 150);

    button.backgroundColor = [UIColorredColor];

    [button addTarget:selfaction:@selector(buttonAction)forControlEvents:UIControlEventTouchDragInside];

    [self.viewaddSubview:button];

    

    NSLog(@"a");

    

    //UIImage - 专门用来管理图片的类,本身不具备显示功能

    //UIImageView- 专门用来显示图片的视图

    //添加图片的2中方法

    //1 

//    UIImage *image = [UIImage imageNamed:@"image4.jpg"];

//    UIImageView *imagev = [[ UIImageView alloc]initWithImage:image];

//    imagev.frame =  self.view.frame;

//    [self.view addSubview:imagev];

//    [imagev release];

    //2 常用

//    UIImageView *imagev = [[UIImageView alloc]initWithFrame:CGRectMake(30, 30, 300, 500)];

//    imagev.image = [UIImage imageNamed:@"image9.jpg"];

//    [self.view addSubview:imagev];

//    [imagev release];

    

    

    

    

    

    

    

    

    

    

    

    // Do any additional setup after loading the view.

}

- (void)buttonAction

{

    //三下回车 秘诀  选中最后一组,3次回车

    SecondViewController *secondVC = [[SecondViewControlleralloc]init];

    //切换页面

    //参数1,要切换的界面

    //参数2,是否需要动画特效

    //参数3 , block -

    

    

    [selfpresentViewController:secondVC animated:YEScompletion:^{

        

        //切换完成调用

       // NSLog(@"%d", __LINE__);

    }];

    

    //presentViewController会引起引用计数增加

   // NSLog(@"%ld", secondVC.retainCount);

    //先执行完成此方法(buttonAction),再去切换界面

   // NSLog(@"%d", __LINE__);

    [secondVC release];

    

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    

    NSLog(@"接受内存告警");

    // Dispose of any resources that can be recreated.

}


/*

#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end

//

//  SecondViewController.m

//  Ui03  - UIimageView

//

//  Created by dllo on 15/11/10.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import "SecondViewController.h"


@interface SecondViewController ()


@end


@implementation SecondViewController



- (void)viewDidLoad {

    [superviewDidLoad];

    self.view.backgroundColor = [UIColorgreenColor];

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];

    button.frame = CGRectMake(150, 150, 150, 150);

    button.backgroundColor = [UIColorredColor];

    [button addTarget:selfaction:@selector(buttonAction)forControlEvents:UIControlEventTouchDragInside];

    [self.viewaddSubview:button];

    NSLog(@"bbb");

    

    // Do any additional setup after loading the view.

}

- (void)buttonAction

{

    //切回原来界面

    //参数1 -是否需要动画

    //参数2 - block-切换完成调用

    //注意新建的rootVc的方式是切换到新的rootVC界面,而非切回原来的rootVC界面

    [selfdismissViewControllerAnimated:YEScompletion:^{

        

        //NSLog(@"%d", __LINE__);

    }];

   // NSLog(@"%d", __LINE__);

}

- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*

#pragma mark - Navigation

 

 


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end


//

//  RootView.m

//  Ui03  - UIimageView

//

//  Created by dllo on 15/11/10.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import "RootView.h"


@implementation RootView

- (instancetype)initWithFrame:(CGRect)frame

{

    self = [superinitWithFrame:frame];

    if (self) {

        [selfcreateSubviews];

    }

    return self;

}

- (void)createSubviews

{

    //UIImage - 专门用来管理图片的类,本身不具备显示功能

    //UIImageView- 专门用来显示图片的视图

    //添加图片的2中方法

    //1

    //    UIImage *image = [UIImage imageNamed:@"image4.jpg"];

    //    UIImageView *imagev = [[ UIImageView alloc]initWithImage:image];

    //    imagev.frame =  self.view.frame;

    //    [self.view addSubview:imagev];

    //    [imagev release];

    //2 常用

    self.backgroundColor = [UIColorwhiteColor];

    UIImageView *imagev = [[UIImageViewalloc]initWithFrame:CGRectMake(30, 30, 300,500)];

    imagev.image = [UIImageimageNamed:@"image9.jpg"];

    [self addSubview:imagev];

    [imagev release];


    

}

@end




0 0
原创粉丝点击