Skip to content

Commit

Permalink
修改播放器全屏
Browse files Browse the repository at this point in the history
  • Loading branch information
renzifeng committed Jul 12, 2020
1 parent b63350b commit e4347df
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 37 deletions.
5 changes: 0 additions & 5 deletions ZFPlayer/Classes/Core/ZFPlayerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ - (void)playerManagerCallbcak {

self.currentPlayerManager.playerPlayStateChanged = ^(id _Nonnull asset, ZFPlayerPlaybackState playState) {
@strongify(self)
if (playState == ZFPlayerPlayStatePlayStopped) {
CGSize size = self.currentPlayerManager.view.frame.size;

self.orientationObserver.presentationSize = size;
}
if (self.playerPlayStateChanged) self.playerPlayStateChanged(asset, playState);
if ([self.controlView respondsToSelector:@selector(videoPlayer:playStateChanged:)]) {
[self.controlView videoPlayer:self playStateChanged:playState];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ @interface ZFPlayerPersentInteractiveTransition () <UIGestureRecognizerDelegate>

@implementation ZFPlayerPersentInteractiveTransition


- (void)addPanGestureForViewController:(UIViewController *)viewController
contentView:(UIView *)contenView
containerView:(UIView *)containerView {
Expand Down
42 changes: 35 additions & 7 deletions ZFPlayer/Classes/Core/ZFPlayerPresentTransition.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ @interface ZFPlayerPresentTransition ()
@property (strong, nonatomic) ZFPlayerView *contentView;
@property (assign, nonatomic) ZFPresentTransitionType type;
@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, assign, getter=isTransiting) BOOL transiting;
@property (nonatomic, assign, getter=isFullScreen) BOOL fullScreen;
@property (nonatomic, assign, getter=isSizeChanged) BOOL sizeChanged;

@end

Expand Down Expand Up @@ -67,6 +70,8 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
* 实现present动画
*/
- (void)presentAnimation:(id<UIViewControllerContextTransitioning>)transitionContext {
self.sizeChanged = NO;

UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
if ([fromVC isKindOfClass:[UINavigationController class]]) {
Expand Down Expand Up @@ -95,18 +100,22 @@ - (void)presentAnimation:(id<UIViewControllerContextTransitioning>)transitionCon
toVC.view.alpha = 1;
[self.delagate zf_orientationWillChange:YES];

CGFloat videoWidth = self.fullScreenScaleSize.width;
CGFloat videoHeight = self.fullScreenScaleSize.height;
CGRect toRect = CGRectMake((ZFPlayerScreenWidth - videoWidth) / 2.0, (ZFPlayerScreenHeight - videoHeight) / 2.0, videoWidth, videoHeight);
NSLog(@"sssssss===origin=%@\n to =%@", NSStringFromCGRect(originRect),NSStringFromCGRect(toRect));
// [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
[UIView animateWithDuration:2 animations:^{
CGRect toRect = [self contentViewFullScreenRect];
self.transiting = YES;
self.fullScreen = NO;
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
self.contentView.frame = toRect;
[self.contentView layoutIfNeeded];
toVC.view.backgroundColor = [tempColor colorWithAlphaComponent:1.f];
} completion:^(BOOL finished) {
self.transiting = NO;
self.fullScreen = YES;
[transitionContext completeTransition:YES];
[self.delagate zf_orientationDidChanged:YES];
if (self.sizeChanged) {
self.contentView.frame = [self contentViewFullScreenRect];
[self.contentView layoutIfNeeded];
}
}];
}

Expand Down Expand Up @@ -139,7 +148,8 @@ - (void)dismissAnimation:(id<UIViewControllerContextTransitioning>)transitionCon
CGRect toRect = [self.containerView convertRect:self.containerView.bounds toView:toVC.view];
[fromVC.view convertRect:self.contentView.bounds toView:self.containerView.window];
[self.delagate zf_orientationWillChange:NO];

self.transiting = YES;
self.fullScreen = YES;
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
fromVC.view.alpha = 0;
self.contentView.frame = toRect;
Expand All @@ -149,7 +159,25 @@ - (void)dismissAnimation:(id<UIViewControllerContextTransitioning>)transitionCon
self.contentView.frame = self.containerView.bounds;
[transitionContext completeTransition:YES];
[self.delagate zf_orientationDidChanged:NO];
self.transiting = NO;
self.fullScreen = NO;
}];
}

- (void)setFullScreenScaleSize:(CGSize)fullScreenScaleSize {
_fullScreenScaleSize = fullScreenScaleSize;
if (!self.transiting && self.isFullScreen) {
self.contentView.frame = [self contentViewFullScreenRect];
} else if (self.transiting && !self.isFullScreen) {
self.sizeChanged = YES;
}
}

- (CGRect)contentViewFullScreenRect {
CGFloat videoWidth = self.fullScreenScaleSize.width;
CGFloat videoHeight = self.fullScreenScaleSize.height;
CGRect rect = CGRectMake((ZFPlayerScreenWidth - videoWidth) / 2.0, (ZFPlayerScreenHeight - videoHeight) / 2.0, videoWidth, videoHeight);
return rect;
}

@end
2 changes: 0 additions & 2 deletions ZFPlayer/Classes/Core/ZFPlayerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

@property (nonatomic, assign) CGSize presentationSize;

//@property (nonatomic, assign) CGSize fullScreenScaleSize;

@property (nonatomic, assign) ZFPlayerScalingMode scalingMode;

@property (nonatomic, assign) ZFPlayerLoadState loadState;
Expand Down
17 changes: 0 additions & 17 deletions ZFPlayer/Classes/Core/ZFPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,6 @@ - (CGSize)presentationSize {
return _presentationSize;
}

//- (CGSize)fullScreenScaleSize {
// CGFloat videoWidth = self.presentationSize.width;
// CGFloat videoHeight = self.presentationSize.height;
// CGFloat screenScale = (CGFloat)(ZFPlayerScreenWidth/ZFPlayerScreenHeight);
// CGFloat videoScale = (CGFloat)(videoWidth/videoHeight);
// if (screenScale > videoScale) {
// CGFloat height = ZFPlayerScreenHeight;
// CGFloat width = (CGFloat)(height * videoScale);
// _fullScreenScaleSize = CGSizeMake(width, height);
// } else {
// CGFloat width = ZFPlayerScreenWidth;
// CGFloat height = (CGFloat)(width / videoScale);
// _fullScreenScaleSize = CGSizeMake(width, height);
// }
// return _fullScreenScaleSize;
//}

- (UIImageView *)coverImageView {
if (!_coverImageView) {
_coverImageView = [[UIImageView alloc] init];
Expand Down
6 changes: 0 additions & 6 deletions ZFPlayer/Classes/Core/ZFPortraitViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@ - (void)setEnablePortraitGesture:(BOOL)enablePortraitGesture {
- (void)setPresentationSize:(CGSize)presentationSize {
_presentationSize = presentationSize;
self.transition.fullScreenScaleSize = self.fullScreenScaleSize;
if (self.isFullScreen) {
CGFloat videoWidth = self.fullScreenScaleSize.width;
CGFloat videoHeight = self.fullScreenScaleSize.height;
self.contentView.frame = CGRectMake(0, 0, videoWidth, videoHeight);
self.contentView.center = self.view.center;
}
}

- (CGSize)fullScreenScaleSize {
Expand Down

0 comments on commit e4347df

Please sign in to comment.