VLCPlaybackInfoTVViewController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*****************************************************************************
  2. * VLC for iOS
  3. *****************************************************************************
  4. * Copyright (c) 2015 VideoLAN. All rights reserved.
  5. * $Id$
  6. *
  7. * Authors: Tobias Conradi <videolan # tobias-conradi.de>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. #import "VLCPlaybackInfoTVViewController.h"
  12. #import "VLCPlaybackInfoRateTVViewController.h"
  13. #import "VLCPlaybackInfoAudioTVViewController.h"
  14. #import "VLCPlaybackInfoTVAnimators.h"
  15. // just for appearance reasons
  16. @interface VLCPlaybackInfoTVTabBarController : UITabBarController
  17. @end
  18. @implementation VLCPlaybackInfoTVTabBarController
  19. @end
  20. @implementation VLCPlaybackInfoTVViewController
  21. - (NSArray<UIViewController*>*)tabViewControllers
  22. {
  23. return @[
  24. [[VLCPlaybackInfoRateTVViewController alloc] initWithNibName:nil bundle:nil],
  25. [[VLCPlaybackInfoAudioTVViewController alloc] initWithNibName:nil bundle:nil],
  26. ];
  27. }
  28. - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  29. {
  30. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  31. if (self) {
  32. self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
  33. }
  34. return self;
  35. }
  36. - (void)viewDidLoad
  37. {
  38. [super viewDidLoad];
  39. [self setupTabBarItemAppearance];
  40. UITabBarController *controller = [[VLCPlaybackInfoTVTabBarController alloc] init];
  41. controller.delegate = self;
  42. controller.viewControllers = [self tabViewControllers];
  43. self.tabBarController = controller;
  44. [self addChildViewController:controller];
  45. controller.view.frame = self.containerView.bounds;
  46. controller.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  47. [self.containerView addSubview:controller.view];
  48. [controller didMoveToParentViewController:self];
  49. UISwipeGestureRecognizer *swipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUpRecognized:)];
  50. swipeUpRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
  51. swipeUpRecognizer.delegate = self;
  52. [self.view addGestureRecognizer:swipeUpRecognizer];
  53. }
  54. - (BOOL)shouldAutomaticallyForwardAppearanceMethods
  55. {
  56. return YES;
  57. }
  58. - (void)updateViewConstraints
  59. {
  60. [super updateViewConstraints];
  61. UIViewController *viewController = self.tabBarController.selectedViewController;
  62. CGFloat tabBarHeight = CGRectGetHeight(self.tabBarController.tabBar.bounds);
  63. self.tabBarRegiomHeightConstraint.constant = tabBarHeight;
  64. CGFloat controllerHeight = viewController.preferredContentSize.height;
  65. self.containerHeightConstraint.constant = controllerHeight;
  66. }
  67. - (void)setupTabBarItemAppearance
  68. {
  69. UITabBarItem *tabBarItemApprearance = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[[VLCPlaybackInfoTVTabBarController class]]];
  70. NSDictionary *attributesSelected = @{NSForegroundColorAttributeName : [UIColor colorWithWhite:0.75 alpha:1.0]};
  71. [tabBarItemApprearance setTitleTextAttributes:attributesSelected forState:UIControlStateSelected];
  72. NSDictionary *attributesFocused = @{NSForegroundColorAttributeName : [UIColor colorWithWhite:1.0 alpha:1.0]};
  73. [tabBarItemApprearance setTitleTextAttributes:attributesFocused forState:UIControlStateFocused];
  74. }
  75. - (void)swipeUpRecognized:(UISwipeGestureRecognizer *)recognizer
  76. {
  77. [self dismissViewControllerAnimated:YES completion:nil];
  78. }
  79. #pragma mark - GestureRecognizerDelegate
  80. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
  81. {
  82. // FIXME: is there any other way to figure out if the tab bar item is currenlty focused?
  83. UIView *view = [[UIScreen mainScreen] focusedView];
  84. while (view) {
  85. if ([view isKindOfClass:[UITabBar class]]) {
  86. return YES;
  87. }
  88. view = view.superview;
  89. }
  90. return NO;
  91. }
  92. #pragma mark - TabBarControllerDelegate
  93. - (nullable id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController
  94. animationControllerForTransitionFromViewController:(UIViewController *)fromVC
  95. toViewController:(UIViewController *)toVC
  96. {
  97. VLCPlaybackInfoTabBarTVTransitioningAnimator* animator = [[VLCPlaybackInfoTabBarTVTransitioningAnimator alloc] init];
  98. animator.infoContainerViewController = self;
  99. return animator;
  100. }
  101. @end