码迷,mamicode.com
首页 > 其他好文 > 详细

167实现全屏显示效果

时间:2015-06-17 17:54:55      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

效果如下:

技术分享

ViewController.h

1 #import <UIKit/UIKit.h>
2 
3 @interface ViewController : UIViewController
4 @end

ViewController.m

 1 #import "ViewController.h"
 2 
 3 @interface ViewController ()
 4 - (void)layoutUI;
 5 @end
 6 
 7 @implementation ViewController
 8 #define kApplicationFrame [[UIScreen mainScreen] applicationFrame]
 9 #define kBounds [[UIScreen mainScreen] bounds]
10 
11 - (void)viewDidLoad {
12     [super viewDidLoad];
13     
14     [self layoutUI];
15 }
16 
17 - (void)didReceiveMemoryWarning {
18     [super didReceiveMemoryWarning];
19     // Dispose of any resources that can be recreated.
20 }
21 
22 - (void)layoutUI {
23     self.navigationItem.title = @"实现全屏显示效果";
24     self.view.backgroundColor = [UIColor whiteColor];
25     
26     UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ImageForBlend"]];
27     imgV.frame = kApplicationFrame;
28     imgV.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; //在旋转屏幕时,能自动适应宽高
29     [self.view addSubview:imgV];
30     
31     NSLog(@"applicationFrame(%0.2f, %0.2f, %0.2f, %0.2f)",
32           kApplicationFrame.origin.x,
33           kApplicationFrame.origin.y,
34           kApplicationFrame.size.width,
35           kApplicationFrame.size.height); //applicationFrame(0.00, 20.00, 375.00, 647.00),会计算状态条的高度20.00点素
36     
37     NSLog(@"bounds(%0.2f, %0.2f, %0.2f, %0.2f)",
38           kBounds.origin.x,
39           kBounds.origin.y,
40           kBounds.size.width,
41           kBounds.size.height); //bounds(0.00, 0.00, 375.00, 667.00)
42 }
43 
44 - (void)viewWillAppear:(BOOL)animated {
45     [super viewWillAppear:animated];
46     
47     [self.navigationController setNavigationBarHidden:NO animated:animated];
48     [self.navigationController setToolbarHidden:NO animated:animated];
49 }
50 
51 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
52     static BOOL isFullScreen = NO;
53     isFullScreen = !isFullScreen;
54     //根据是否全屏显示isFullScreen,显示或隐藏状态条、导航条、工具条
55     [[UIApplication sharedApplication] setStatusBarHidden:isFullScreen withAnimation:YES];  //必须设置Info.plist的新项View controller-based status bar appearance对应值为NO,才能有效控制状态条
56     [self.navigationController setNavigationBarHidden:isFullScreen animated:YES];
57     [self.navigationController setToolbarHidden:isFullScreen animated:YES];
58 }
59 
60 @end

AppDelegate.h

1 #import <UIKit/UIKit.h>
2 
3 @interface AppDelegate : UIResponder <UIApplicationDelegate>
4 @property (strong, nonatomic) UIWindow *window;
5 @property (strong, nonatomic) UINavigationController *navigationController;
6 
7 @end

AppDelegate.m

 1 #import "AppDelegate.h"
 2 #import "ViewController.h"
 3 
 4 @interface AppDelegate ()
 5 @end
 6 
 7 @implementation AppDelegate
 8 
 9 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
10     _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
11     ViewController *viewController = [[ViewController alloc] init];
12     _navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
13     _window.rootViewController = _navigationController;
14     //[_window addSubview:_navigationController.view]; //当_window.rootViewController关联时,这一句可有可无
15     [_window makeKeyAndVisible];
16     return YES;
17 }
18 
19 - (void)applicationWillResignActive:(UIApplication *)application {
20 }
21 
22 - (void)applicationDidEnterBackground:(UIApplication *)application {
23 }
24 
25 - (void)applicationWillEnterForeground:(UIApplication *)application {
26 }
27 
28 - (void)applicationDidBecomeActive:(UIApplication *)application {
29 }
30 
31 - (void)applicationWillTerminate:(UIApplication *)application {
32 }
33 
34 @end

 

167实现全屏显示效果

标签:

原文地址:http://www.cnblogs.com/huangjianwu/p/4583958.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!