01-modal Demo示例程序源代码
- 源代码下载链接:01-modal.zip
37.8 KB -
// MJAppDelegate.h
- //
- // MJAppDelegate.h
- // 01-modal
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @interfaceMJAppDelegate : UIResponder <UIApplicationDelegate>
- @property(strong,nonatomic) UIWindow *window;
- @end
-
// MJAppDelegate.m
Map - //
- // MJAppDelegate.m
- // 01-modal
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJAppDelegate.h"
- #import"MJOneViewController.h"
- @implementationMJAppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- self.window.rootViewController = [[MJOneViewController alloc] init];
- [self.window makeKeyAndVisible];
- returnYES;
- }
- - (void)applicationWillResignActive:(UIApplication *)application
- {
- // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
- }
- - (void)applicationDidEnterBackground:(UIApplication *)application
- {
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- }
- - (void)applicationWillEnterForeground:(UIApplication *)application
- {
- // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application
- {
- // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
- }
- - (void)applicationWillTerminate:(UIApplication *)application
- {
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
- }
- @end
-
// MJOneViewController.h
Map - //
- // MJOneViewController.h
- // 01-modal
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @interfaceMJOneViewController : UIViewController
- - (IBAction)jump2;
- @end
-
// MJOneViewController.m
Map - //
- // MJOneViewController.m
- // 01-modal
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJOneViewController.h"
- #import"MJTwoViewController.h"
- #import"MJThreeViewController.h"
- @interfaceMJOneViewController ()
- @end
- @implementationMJOneViewController
- //- (IBAction)jump2 {
- // MJTwoViewController *two = [[MJTwoViewController alloc] init];
- //
- // // modalTransitionStyle设置模态控制器展示的形式
- // /*
- // UIModalTransitionStyleCoverVertical = 0, 垂直覆盖(从底部钻上来)
- // UIModalTransitionStyleFlipHorizontal, 水平翻转
- // UIModalTransitionStyleCrossDissolve, 淡入淡出
- // UIModalTransitionStylePartialCurl 翻页(展示部分界面)
- // */
- //// two.modalTransitionStyle = UIModalTransitionStylePartialCurl;
- ////本文永久链接,转载请注明出处:http://www.cnblogs.com/ChenYilong/p/3490807.html
- // //以modal形式展示其他控制器(模态窗口)
- // [self presentViewController:two animated:YES completion:^{
- // NSLog(@"----展示完毕");
- // }];
- //}
- /*
- 给一个控制器顶部增加一个导航栏的最快方法:
- 1>给这个控制器包装一个导航控制器(UINavigationController)
- */
- - (void)jump2
- {
- MJThreeViewController *three = [[MJThreeViewController alloc] init];
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:three];
- nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
- NSLog(@"前:one = %p, window的子控件%@",self.view, [UIApplication sharedApplication].keyWindow.subviews);
- [selfpresentViewController:nav animated:YEScompletion:^{
- NSLog(@"后:nav=%p, %@", nav.view, [UIApplication sharedApplication].keyWindow.subviews);
- }];
- }
- @end
-
// MJTwoViewController.h
Map - //
- // MJTwoViewController.h
- // 01-modal
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @interfaceMJTwoViewController : UIViewController
- - (IBAction)cancel:(id)sender;
- @end
-
// MJTwoViewController.m
Map - //
- // MJTwoViewController.m
- // 01-modal
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJTwoViewController.h"
- @interfaceMJTwoViewController ()
- @end
- @implementationMJTwoViewController
- - (void)viewDidLoad
- {
- [superviewDidLoad];
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
- btn.frame = CGRectMake(0,44,40,40);
- [self.view addSubview:btn];
- }
- - (IBAction)cancel:(id)sender {
- //关闭当前的模态控制器
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- @end
-
// MJThreeViewController.h
Map - //
- // MJThreeViewController.h
- // 01-modal
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import<UIKit/UIKit.h>
- @interface MJThreeViewController : UIViewController
- @end
-
// MJThreeViewController.m
Map - //
- // MJThreeViewController.m
- // 01-modal
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年itcast. All rights reserved.
- //
- #import"MJThreeViewController.h"
- @interface MJThreeViewController ()
- @end
- @implementationMJThreeViewController
- - (void)viewDidLoad
- {
- [superviewDidLoad];
- UIView *abc = [[UIView alloc] init];
- abc.frame = CGRectMake(0,0,100,100);
- abc.backgroundColor = [UIColor yellowColor];
- [self.view addSubview:abc];
- //本文永久链接,转载请注明出处:http://www.cnblogs.com/ChenYilong/p/3490807.html
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消"style:UIBarButtonItemStyleBordered target:selfaction:@selector(cancel)];
- }
- - (void)cancel
- {
- [selfdismissViewControllerAnimated:YEScompletion:nil];
- }
- @end
作者:
出处:http://www.cnblogs.com/ChenYilong/(点击RSS订阅)
本文版权归作者和博客园共有,欢迎转载,
但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。