有没有简单的方法来实现YTPlayer,如开合效果?我试过Facebook流行动画,但无法成功。以下是我尝试过的一些代码:
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"];
我的意思是说YTPlayer就像动画一样: 1.开场效果:点击视频时,视频应逐渐覆盖整个屏幕。同时,背景也应该这样做。 2.结束效果:点击完成后,视频应逐渐消失,并在表视图或集合视图中返回其先前的位置。
谢谢:)
答案 0 :(得分:1)
您可以在此处安装一个pod调用YTPlayer:https://cocoapods.org/pods/youtube-ios-player-helper
或者您可以直接从这里获取文件:https://github.com/youtube/youtube-ios-player-helper
它没有很好的文档记录,但您只需要通过Youtube视频ID。此套餐确实非常好地执行YouTube效果。