1

Is there any simple way to achieve YTPlayer like opening-closing effects? I tried Facebook pop animation but could not be successful. Here are some code that I tried:

UIView *fromView = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey].view;
fromView.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
fromView.userInteractionEnabled = NO;
NSLog(@"Screen center: %f %ld",SCREEN_HEIGHT,(long)SCREEN_WIDTH);

NSLog(@"fromView center : %@", NSStringFromCGPoint(fromView.center));

UIView *toView = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view;                          CGRectGetWidth(transitionContext.containerView.bounds),

NSLog(@"Transition context center: %@", NSStringFromCGPoint(transitionContext.containerView.center));
//toView.center = CGPointMake(transitionContext.containerView.center.x, transitionContext.containerView.center.y);
toView.center = CGPointMake(0,0);
[transitionContext.containerView addSubview:toView];
NSLog(@"toView center : %@", NSStringFromCGPoint(toView.center));

POPSpringAnimation* scaleAnimationY = [POPSpringAnimation animationWithPropertyNamed:kPOPScrollViewZoomScale];
scaleAnimationY.fromValue = @(0);
scaleAnimationY.toValue=@(1);

POPSpringAnimation* scaleAnimationX = [POPSpringAnimation animationWithPropertyNamed:kPOPScrollViewZoomScale];
scaleAnimationX.fromValue = @(0);
scaleAnimationX.toValue=@(1);


POPSpringAnimation *positionAnimationY = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];
positionAnimationY.fromValue = @(self.view.frame.origin.y);
positionAnimationY.toValue = @(0);
positionAnimationY.springBounciness = 0;
[positionAnimationY setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
    [transitionContext completeTransition:YES];
}];

NSLog(@"positionAnimationY fromValue,toValue : %@ %@", positionAnimationY.fromValue, positionAnimationY.toValue);

POPSpringAnimation *positionAnimationX = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionX];
positionAnimationX.fromValue = @(self.view.frame.origin.x);
positionAnimationX.toValue = @(SCREEN_WIDTH);
positionAnimationX.springBounciness = 0;
[positionAnimationX setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
    //[transitionContext completeTransition:YES];
}];

NSLog(@"positionAnimationX fromValue, toValue : %@ %@", positionAnimationX.fromValue, positionAnimationX.toValue);

POPSpringAnimation *positionAnimation1Y = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];
positionAnimation1Y.fromValue = @(self.view.frame.origin.y);
positionAnimation1Y.toValue = @(SCREEN_HEIGHT);
positionAnimation1Y.springBounciness = 0;
[positionAnimation1Y setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
    [transitionContext completeTransition:YES];
}];
[toView.layer pop_addAnimation:scaleAnimationY forKey:@"scaleAnimationY"];
[toView.layer pop_addAnimation:scaleAnimationX forKey:@"scaleAnimationX"];

What I mean by saying YTPlayer like animations: 1. Opening effect: When clicked upon video, video should gradually cover entire screen. In the same time, background should do same. 2. Closing effect: When clicked upon done, video should gradually vanish and get back its previous place in table view or collection view.

Thanks :)

JAL
  • 41,701
  • 23
  • 172
  • 300
Emrah Akgül
  • 630
  • 2
  • 7
  • 18

1 Answers1

1

You can install a pod call YTPlayer found here: https://cocoapods.org/pods/youtube-ios-player-helper

Or you can get the files directly from here: https://github.com/youtube/youtube-ios-player-helper

It is not very well documented, however you simply need to pass through the Youtube video id. This package does perform the YouTube effect exceptionally well.

enter image description here

App Dev Guy
  • 5,396
  • 4
  • 31
  • 54
  • But, I guess this is only for youtube videos. I need these opening and closing effects for already uploaded videos. – Emrah Akgül Dec 22 '15 at 09:05
  • You can alter the functionality if you need, I would have a look through the code in the files, the ground work has been laid so manipulate for your preference. Bare in mind you should only do this if it is not a pod install. Pod installs can be updated and you will lose any alterations you make. – App Dev Guy Dec 22 '15 at 09:08