您的位置:首页 > 产品设计 > UI/UE

IOS模态视图 (UI页面切换)

2016-01-05 20:13 656 查看
目录如下




首先添加一个新工程ModalViewController.m/h

1.



2.



在ViewController.m文件

// Copyright © 2016年 1.05. All rights reserved.

//

#import "ViewController.h"

#import "ModalViewController.h"

@interface
ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[superviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

//添加弹出模态视图按钮

UIButton *button=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

[button setFrame:CGRectMake(120,220,80,
40)];

//按钮的背景颜色

[button setBackgroundColor:[UIColorcyanColor]];

//按钮的标题

[button setTitle:@"模态"forState:UIControlStateNormal];

//添加事件

[button addTarget:selfaction:@selector(biantai)forControlEvents:UIControlEventTouchUpInside];

[self.viewaddSubview:button];

}

-(void)biantai

//为视图按钮添加弹出模态视图方法

{

ModalViewController *modalView=[[ModalViewControlleralloc]init];

modalView.modalTransitionStyle=UIModalTransitionStyleCoverVertical;

// UIModalTransitionStyleCoverVertical:画面从下向上徐徐弹出,关闭时向下隐藏(默认方式)。

//UIModalTransitionStyleFlipHorizontal:从前一个画面的后方,以水平旋转的方式显示后一画面。

//UIModalTransitionStyleCrossDissolve:前一画面逐渐消失的同时,后一画面逐渐显示。

// UIModalTransitionStylePartialCurl:从下往上以翻页的形式显示下一页面.

//从下往上推出viewController

[selfpresentViewController:modalViewanimated:YEScompletion:nil];

}

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

在ModalViewController.m文件中

// Copyright © 2016年 1.05. All rights reserved.

//

#import "ModalViewController.h"

@interface
ModalViewController ()

@end

@implementation ModalViewController

- (void)viewDidLoad {

[superviewDidLoad];

// Do any additional setup after loading the view.

//给view添加背景

self.view.backgroundColor=[UIColormagentaColor];

//创建button对象

UIButton * button=[[UIButtonalloc]initWithFrame:CGRectMake(130,50,60,
20)];

//button标题

[button setTitle:@"返回"forState:UIControlStateNormal];

//添加事件

[button addTarget:selfaction:@selector(fanhui)forControlEvents:UIControlEventTouchUpInside];

[self.viewaddSubview:button];

}

-(void)fanhui

{

//将弹出的模态视图移除,第一yes表示移除的时候有动画效果,第二个参数是设置一个回调,当模态视图移除消失后,会回到这里,可以在这里写句话,打个断点,判断是否回调

//从上往下返回viewController

[selfdismissViewControllerAnimated:YEScompletion:^{

NSLog(@"back");

}];

}

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

大功告成

,颜色弄成这样,也就将就了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: