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
大功告成
,颜色弄成这样,也就将就了
首先添加一个新工程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
大功告成
,颜色弄成这样,也就将就了
相关文章推荐
- easyui combobox级联(转载)
- iOS开发学习之UI篇3、UILabel
- leetcode第一刷_Unique Paths
- 优化UITableViewCell高度计算的那些事 附源码
- (转载)iOS UILabel自定义行间距时获取高度
- IOS(UI)_UIButton(按钮)和UIImageView(图片按钮)
- iOS开发学习之UI篇 1、UIView
- IOS(UI)_UILabel(标签)
- UE 无法初始化FTP组件
- 有value时,li元素序列号就是value值,没有value,则会递增
- 关于百度 UEditor的使用
- Android can only be built by versions 3.81 and 3.82
- Arduino 中断和定时器
- lintcode :implement queue by two stacks 用栈实现队列
- UIAlertController
- UIView设置指定的border
- 给UIView 的子类们 UIButton UILbel等 。。。。加一个虚线圆角的border
- wifi模块ESP8266_AT arduino 库文件部分方法解析及优化
- iOS中xcode的调试技巧(打印UI层次、po)
- 项目文件包含 ToolsVersion="12.0" 设置,而此版本的 MSBuild 不支持该工具版本