iOS开发-模式视图
2014-01-13 20:32
501 查看
在iOS中视图切换最简单一个估计就是模式视图了,下面简单演示一下模式视图:
1.新建一个空的工程,新建一个MainViewController类和一个SubViewController类
2.在AppDelegate.m中:
3.在MainViewController.m中
4.在SubViewController.m中
1.新建一个空的工程,新建一个MainViewController类和一个SubViewController类
2.在AppDelegate.m中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; MainViewController *mvc = [[MainViewController alloc] init]; self.window.rootViewController = mvc; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; }
3.在MainViewController.m中
- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor yellowColor]; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(10, 10, 300, 40); [button setTitle:@"切换视图" forState:UIControlStateNormal]; [button addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } - (void)btnClick { SubViewController *svc = [[SubViewController alloc] init];
svc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;//动画效果[self presentViewController:svc animated:YES completion:^{}];//切换到下一个视图}
4.在SubViewController.m中
- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor redColor]; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(10, 10, 300, 40); [button setTitle:@"返回主视图" forState:UIControlStateNormal]; [button addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } - (void)btnClick { [self dismissViewControllerAnimated:YES completion:^{}];//返回上一个视图 }
相关文章推荐
- IOS界面切换
- 【iOS开发】UIView之间常用视图之间切换方式
- 使用RNSwipeViewController类库进行视图切换 推荐
- presentViewController显示方式的窗口,没有导航栏的解决方法
- iOS UIViewController之间的切换
- UIView的试图切换
- 自定义转场效果 presentViewController实现由左向右
- dismissViewController 实现多个模态VC跳转到根VC
- Swift 解决dismissViewControllerAnimated关闭当前Controller无效的问题
- iOS 关于presentViewController弹出页面反应迟钝的问题
- 一次性dismiss多个viewcontroller
- dismissViewControllerAnimated:completion:
- 模态弹窗,点击黑色半透明区域消失
- 改变模态弹窗的大小
- 怎样快速切换iMindMap视图
- PresentViewController切换界面
- iOS开发中Block的使用
- ios开源项目(各种有用的第三方库)
- IOS 用户登录界面
- iOS - 程序内调节音量: