YYAppDelegate.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // AppDelegate.m
  3. // YYKitExample
  4. //
  5. // Created by ibireme on 14-9-18.
  6. // Copyright (c) 2014 ibireme. All rights reserved.
  7. //
  8. #import "YYAppDelegate.h"
  9. #import "YYRootViewController.h"
  10. /// Fix the navigation bar height when hide status bar.
  11. @interface YYExampleNavBar : UINavigationBar
  12. @end
  13. @implementation YYExampleNavBar {
  14. CGSize _previousSize;
  15. }
  16. - (CGSize)sizeThatFits:(CGSize)size {
  17. size = [super sizeThatFits:size];
  18. if ([UIApplication sharedApplication].statusBarHidden) {
  19. size.height = 64;
  20. }
  21. return size;
  22. }
  23. - (void)layoutSubviews {
  24. [super layoutSubviews];
  25. if (!CGSizeEqualToSize(self.bounds.size, _previousSize)) {
  26. _previousSize = self.bounds.size;
  27. [self.layer removeAllAnimations];
  28. [self.layer.sublayers makeObjectsPerformSelector:@selector(removeAllAnimations)];
  29. }
  30. }
  31. @end
  32. @interface YYExampleNavController : UINavigationController
  33. @end
  34. @implementation YYExampleNavController
  35. - (BOOL)shouldAutorotate {
  36. return YES;
  37. }
  38. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  39. return UIInterfaceOrientationMaskPortrait;
  40. }
  41. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  42. return UIInterfaceOrientationPortrait;
  43. }
  44. @end
  45. @implementation YYAppDelegate
  46. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  47. YYRootViewController *root = [YYRootViewController new];
  48. YYExampleNavController *nav = [[YYExampleNavController alloc] initWithNavigationBarClass:[YYExampleNavBar class] toolbarClass:[UIToolbar class]];
  49. if ([nav respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]) {
  50. nav.automaticallyAdjustsScrollViewInsets = NO;
  51. }
  52. [nav pushViewController:root animated:NO];
  53. self.rootViewController = nav;
  54. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  55. self.window.rootViewController = self.rootViewController;
  56. self.window.backgroundColor = [UIColor grayColor];
  57. [self.window makeKeyAndVisible];
  58. return YES;
  59. }
  60. @end