iOS UI 02 UIimageview 和模态切换

注意这是哪一个文件!!!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 {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

    RootView *rootV = [[RootView alloc]initWithFrame:[[UIScreen mainScreen] bounds] ];

    [self.view addSubview:rootV];

    [rootV release];

    

    

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

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

    button.backgroundColor = [UIColor redColor];

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

    [self.view addSubview: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 = [[SecondViewController alloc]init];

    //切换页面

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

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

    //参数3 , block -

    

    

    [self presentViewController:secondVC animated:YES completion:^{

        

        //切换完成调用

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

    }];

    

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

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

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

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

    [secondVC release];

    

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    

    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 {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor greenColor];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

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

    button.backgroundColor = [UIColor redColor];

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

    [self.view addSubview:button];

    NSLog(@"bbb");

    

    // Do any additional setup after loading the view.

}

- (void)buttonAction

{

    //切回原来界面

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

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

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

    [self dismissViewControllerAnimated:YES completion:^{

        

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

    }];

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

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // 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 = [super initWithFrame:frame];

    if (self) {

        [self createSubviews];

    }

    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 = [UIColor whiteColor];

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

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

    [self addSubview:imagev];

    [imagev release];


    

}

@end




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值