自定义弹出模态视图
来源:互联网 发布:大数据人才缺口 编辑:程序博客网 时间:2024/04/28 18:10
(1)设置根控制器
(2)设置主视图控制器
RootViewController.m
#import "ModelViewController.h"#import "UIViewController+MypresentModal.h"@interface RootViewController ()@end@implementation RootViewController- (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 greenColor]; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(90, 90, 90, 50); button.backgroundColor = [UIColor redColor]; [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; }- (void)buttonAction { ModelViewController *modelCtrl = [[ModelViewController alloc] init]; [self myPresentViewController:modelCtrl]; }
(3)设置模态视图控制器
ModelViewController.m
#import "UIViewController+MypresentModal.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]; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(90, 90, 90, 50); button.backgroundColor = [UIColor redColor]; [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; }- (void)buttonAction { [self myDismissViewController]; }
(4)添加类目
UIViewController+MypresentModal.h
//定义弹出的动画效果- (void)myPresentViewController:(UIViewController *)viewController;//自定义关闭模态视图的动画效果- (void)myDismissViewController;UIViewController+MypresentModal.m
//定义弹出的动画效果- (void)myPresentViewController:(UIViewController *)viewController { //viewController是模态视图控制器 //设置模态视图的frame viewController.view.frame = CGRectMake(320, 0, 320, 480); //取得当前的主window UIWindow *window = [UIApplication sharedApplication].keyWindow; //将视图控制器的视图添加到window上显示 [window addSubview:viewController.view]; //开始动画 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.3]; self.view.frame = CGRectMake(-320, 0, 320, 480); viewController.view.frame = CGRectMake(0, 0, 320, 480); //关闭动画 [UIView commitAnimations]; [self addChildViewController:viewController]; }//自定义关闭模态视图的动画效果- (void)myDismissViewController { UIWindow *window = [UIApplication sharedApplication].keyWindow; //开始动画 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.3]; self.view.frame = CGRectMake(320, 0, 320, 480); //得到模态视图控制器 window.rootViewController.view.frame = CGRectMake(0, 0, 320, 480); [UIView commitAnimations]; [self removeFromParentViewController]; }
0 0
- 自定义弹出模态视图
- 自定义弹出视图
- 弹出模态视图【发微博】、视图的生命周期
- UIAlertView 弹出自定义视图里,位置不正确
- Swift 百度地图自定义弹出视图
- iOS 自定义模态视图
- iOS 自定义弹出视图 几行代码可以自定义任何弹出视图
- 模态视图1-底部弹出分享按钮
- 弹出视图
- 弹出视图
- 弹出视图
- iOS自定义弹出视图,以及简单的手势讲解
- iOS实现自定义的弹出视图(popView)
- iOS实现自定义的弹出视图(popView)
- IOS UI:弹出视图/弹出模态 presentViewController与presentModalViewController(增加IOS 6.0说明)
- IOS UI:弹出视图/弹出模态 presentViewController与presentModalViewController(增加IOS 6.0说明)
- 模态视图那些事(二)之 弹出视图样式
- 点击按钮弹出可自定义小弹框即实现模态窗口
- Python: try finally with 简介
- MATLAB整理代码快捷键
- CGI与Servlet的比较
- Centos安装中文输入法
- Spring依赖注入(DI)的三种实现方式
- 自定义弹出模态视图
- VC 链接Access 数据库 插入变量到表
- Spring 工具类 UrlPathHelper
- 矩阵快速幂锦上添花小结
- 第九周项目5 从键盘输入20个整数,输出它们的和
- Uncover Security Design Flaws Using The STRIDE Approach
- Java Visual VM配置
- 倒置链表(数据结构)
- poj 1147 Binary codes