VLCPlaybackInfoTVViewController.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. @interface VLCPlaybackInfoTVViewController ()
  13. @property (nonatomic) IBOutlet UIView *containerView;
  14. @property (nonatomic) IBOutlet UIView *dimmingView;
  15. @property (nonatomic) IBOutlet NSLayoutConstraint *containerHeightConstraint;
  16. @property (nonatomic) IBOutlet UITabBarController *tabBarController;
  17. @end
  18. @implementation VLCPlaybackInfoTVViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. UITabBarController *controller = [[UITabBarController alloc] init];
  22. [self addChildViewController:controller];
  23. controller.view.frame = self.containerView.bounds;
  24. controller.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  25. [self.containerView addSubview:controller.view];
  26. [controller didMoveToParentViewController:self];
  27. UISwipeGestureRecognizer *swipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUpRecognized:)];
  28. swipeUpRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
  29. [self.view addGestureRecognizer:swipeUpRecognizer];
  30. }
  31. - (BOOL)shouldAutomaticallyForwardAppearanceMethods {
  32. return YES;
  33. }
  34. - (void)swipeUpRecognized:(UISwipeGestureRecognizer *)recognizer {
  35. // TODO: check if it was a navigation gesture in child??
  36. [self dismissViewControllerAnimated:YES completion:nil];
  37. }
  38. @end
  39. @implementation VLCPlaybackInfoTVTransitioningAnimator
  40. - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
  41. return 0.5;
  42. }
  43. - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
  44. UIViewController *source = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
  45. UIViewController *target = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
  46. UIView *container = [transitionContext containerView];
  47. CGRect initialSourceFrame = [transitionContext initialFrameForViewController:source];
  48. // TODO: calculate
  49. CGFloat infoHeight = CGRectGetHeight(initialSourceFrame);
  50. CGRect largeFrame = ({
  51. CGRect frame = initialSourceFrame;
  52. frame.origin.y -=infoHeight;
  53. frame.size.height += infoHeight;
  54. frame;
  55. });
  56. CGRect smallFrame = initialSourceFrame;
  57. CGFloat targetAlpha = 1.0;
  58. CGRect fromFrame = initialSourceFrame;
  59. CGRect toFrame = initialSourceFrame;
  60. VLCPlaybackInfoTVViewController *infoVC = nil;
  61. if ([target isKindOfClass:[VLCPlaybackInfoTVViewController class]]) {
  62. infoVC = (VLCPlaybackInfoTVViewController*) target;
  63. infoVC.dimmingView.alpha = 0.0;
  64. targetAlpha = 1.0;
  65. toFrame = smallFrame;
  66. fromFrame = largeFrame;
  67. [container addSubview:target.view];
  68. } else if ([source isKindOfClass:[VLCPlaybackInfoTVViewController class]]) {
  69. infoVC = (VLCPlaybackInfoTVViewController*) source;
  70. infoVC.dimmingView.alpha = 1.0;
  71. targetAlpha = 0.0;
  72. toFrame = largeFrame;
  73. fromFrame = smallFrame;
  74. }
  75. infoVC.view.frame = fromFrame;
  76. // fallback
  77. if (!infoVC) {
  78. target.view.frame = smallFrame;
  79. }
  80. [UIView animateWithDuration:[self transitionDuration:transitionContext]
  81. animations:^{
  82. infoVC.view.frame = toFrame;
  83. infoVC.dimmingView.alpha = targetAlpha;
  84. }
  85. completion:^(BOOL finished) {
  86. [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
  87. }];
  88. }
  89. @end