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 :)
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.