模态事图

 

#import "RootViewController.h"

#import "ModelViewController.h"

@interfaceRootViewController ()

 

@end

 

@implementation RootViewController

 

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

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    returnself;

}

 

- (void)viewDidLoad

{

    [superviewDidLoad];

    UIButton *present = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    present.frame = CGRectMake(50, 50, 100, 60);

    [present setTitle:@"present"forState:UIControlStateNormal];

    [present addTarget:selfaction:@selector(presentModalVC) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:present];

    

}

-(void)presentModalVC{

    ModelViewController *mvc = [[ModelViewControlleralloc] init];

    //自下向上推出(默认) UIModalTransitionStyleCoverVertical

    //淡入淡出效果 UIModalTransitionStyleCrossDissolve

    //左右翻转 UIModalTransitionStyleFlipHorizontal

    //翻书效果 UIModalTransitionStylePartialCurl 

//    mvc.modalTransitionStyle = UIModalTransitionStylePartialCurl;

    if ([[UIDevicecurrentDevice].systemVersionfloatValue] <6.0f) {

        [selfpresentModalViewController:mvc animated:YES];

    }else{

        [selfpresentViewController:mvc animated:YEScompletion:^{

            NSLog(@"call back");

        }];

    }

    [mvc release];

}

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

@end

 

 

ModalViewController.m

//
//  ModelViewController.m
//  test1
//
//  Created by wei8 on 13-5-27.
//  Copyright (c) 2013年 wei8. All rights reserved.
//

#import "ModelViewController.h"

@interface ModelViewController ()

@end

@implementation ModelViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
    UIButton *dismiss = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    dismiss.frame = CGRectMake(50, 50, 100, 60);
    [dismiss setTitle:@"dismiss" forState:UIControlStateNormal];
    [dismiss addTarget:self action:@selector(dismissModalVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:dismiss];
	// Do any additional setup after loading the view.
}
-(void)dismissModalVC{
    //判断系统版本以执行不同的视图消失方法
    if ([[UIDevice currentDevice].systemVersion floatValue] < 6.0 ) {
        [self dismissModalViewControllerAnimated:YES];
    }else{
        [self dismissViewControllerAnimated:YES completion:^{
            NSLog(@"dismiss call back");
        }];
    }
    
}
-(void)viewWillAppear:(BOOL)animated{
    printf(__FUNCTION__);
    printf("\n");
}
-(void)viewDidAppear:(BOOL)animated{
    printf(__FUNCTION__);
    printf("\n");
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)viewWillDisappear:(BOOL)animated{
    printf(__FUNCTION__);
    printf("\n");
}
-(void)viewDidDisappear:(BOOL)animated{
    printf(__FUNCTION__);
    printf("\n");
}
- (void)dealloc
{
    printf(__FUNCTION__);
    printf("\n");
    [super dealloc];
}
@end

 

 IOS6.0之后的模态视图呈现方法加了块语法。这里先判断系统版本以执行不同的方法。

模态视图消失时执行方法的顺序 

-[ModelViewController viewWillAppear:]
-[ModelViewController viewDidAppear:]
2013-05-27 22:58:11.434 test1[17382:11303] call back
-[ModelViewController viewWillDisappear:]
-[ModelViewController viewDidDisappear:]
-[ModelViewController dealloc]
2013-05-27 22:58:15.908 test1[17382:11303] dismiss call back

 

 //自下向上推出(默认) UIModalTransitionStyleCoverVertical

    //淡入淡出效果 UIModalTransitionStyleCrossDissolve

    //左右翻转 UIModalTransitionStyleFlipHorizontal

    //翻书效果 UIModalTransitionStylePartialCurl 

//    mvc.modalTransitionStyle = UIModalTransitionStylePartialCurl;

 

 

转载于:https://www.cnblogs.com/wei8/archive/2013/05/27/3102780.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值