Skip to content

Commit

Permalink
完善 控制层容器对item的布局.
Browse files Browse the repository at this point in the history
  • Loading branch information
changsanjiang committed Oct 28, 2018
1 parent 7b8edbb commit 5c2b4d8
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 7 deletions.
2 changes: 1 addition & 1 deletion SJVideoPlayer.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'SJVideoPlayer'
s.version = '2.2.0'
s.version = '2.2.1'
s.summary = 'video player.'
s.description = 'https://github.com/changsanjiang/SJVideoPlayer/blob/master/README.md'
s.homepage = 'https://github.com/changsanjiang/SJVideoPlayer'
Expand Down
8 changes: 6 additions & 2 deletions SJVideoPlayer/Adapters/SJEdgeControlLayerAdapters.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, readonly) UIView *leftContainerView;
@property (nonatomic, strong, readonly) UIView *rightContainerView;

/// default is NO.
@property (nonatomic) BOOL showBackgroundColor;
/// default is YES.
@property (nonatomic) BOOL autoAdjustTopSpacing; // 自动调整顶部间距, 让出状态栏

@property (nonatomic) BOOL isFitOnScreen;

#ifdef DEBUG
@property (nonatomic) BOOL showBackgroundColor;
#endif
@end
NS_ASSUME_NONNULL_END
10 changes: 8 additions & 2 deletions SJVideoPlayer/Adapters/SJEdgeControlLayerAdapters.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ - (void)_updateTopLayout:(nullable NSNotification *)notify {
make.height.offset(49);
make.bottom.offset(0);
if (@available(iOS 11.0, *)) {
make.top.equalTo(self.topContainerView.mas_safeAreaLayoutGuideTop);
make.top.equalTo(self.topContainerView.mas_safeAreaLayoutGuideTop).offset(8);
make.left.equalTo(self.topContainerView.mas_safeAreaLayoutGuideLeft);
make.right.equalTo(self.topContainerView.mas_safeAreaLayoutGuideRight);
} else {
make.top.offset(8);
make.top.offset(self.isFitOnScreen?20:8);
make.left.right.offset(0);
}
}];
Expand All @@ -82,6 +82,12 @@ - (void)_updateTopLayout:(nullable NSNotification *)notify {
}
}

- (void)setIsFitOnScreen:(BOOL)isFitOnScreen {
if ( isFitOnScreen == _isFitOnScreen ) return;
_isFitOnScreen = isFitOnScreen;
[self _updateTopLayout:nil];
}

- (SJVideoPlayerControlMaskView *)topContainerView {
if ( _topContainerView ) return _topContainerView;
_topContainerView = [[SJVideoPlayerControlMaskView alloc] initWithStyle:SJMaskStyle_top];
Expand Down
7 changes: 7 additions & 0 deletions SJVideoPlayer/SJEdgeControlLayer/SJEdgeControlLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ - (void)installedControlViewToVideoPlayer:(__kindof SJBaseVideoPlayer *)videoPla
}

- (void)controlLayerNeedAppear:(__kindof SJBaseVideoPlayer *)videoPlayer {
self.isFitOnScreen = CGRectEqualToRect(videoPlayer.view.bounds, UIScreen.mainScreen.bounds);
[self _updateAppearStateForAdapters:videoPlayer];
[self _updateItemsForAdaptersIfNeeded:videoPlayer];
}
Expand Down Expand Up @@ -846,13 +847,19 @@ - (void)loadCompletion:(SJBaseVideoPlayer *)videoPlayer {
- (void)videoPlayer:(__kindof SJBaseVideoPlayer *)videoPlayer willRotateView:(BOOL)isFull {
[self _updateAppearStateForAdapters:videoPlayer];
[self _updateItemsForAdaptersIfNeeded:videoPlayer];
if ( ![self _isHiddenWithView:_bottomProgressSlider] ) [self _hidden:_bottomProgressSlider animated:NO];
}

- (void)videoPlayer:(__kindof SJBaseVideoPlayer *)videoPlayer willFitOnScreen:(BOOL)isFitOnScreen {
self.isFitOnScreen = isFitOnScreen;
[self _updateAppearStateForAdapters:videoPlayer];
[self _updateItemsForAdaptersIfNeeded:videoPlayer];
}

- (void)videoPlayer:(__kindof SJBaseVideoPlayer *)videoPlayer didEndRotation:(BOOL)isFull {
if ( !videoPlayer.controlLayerAppeared ) [self _show:_bottomProgressSlider animated:YES];
}

/// 在`tableView`或`collectionView`上将要显示的时候调用.
- (void)videoPlayerWillAppearInScrollView:(SJBaseVideoPlayer *)videoPlayer {
videoPlayer.view.hidden = NO;
Expand Down
2 changes: 1 addition & 1 deletion SJVideoPlayer/SJVideoPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ - (void)dealloc {
}

+ (NSString *)version {
return @"v2.2.0";
return @"v2.2.1";
}

+ (instancetype)player {
Expand Down
6 changes: 6 additions & 0 deletions SJVideoPlayerProject/SJVideoPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
A6D1A26221845F02006FF2C1 /* ViewController_Adjust.m in Sources */ = {isa = PBXBuildFile; fileRef = A6D1A26021845F02006FF2C1 /* ViewController_Adjust.m */; };
A6D1A26321845F02006FF2C1 /* ViewController_Adjust.xib in Resources */ = {isa = PBXBuildFile; fileRef = A6D1A26121845F02006FF2C1 /* ViewController_Adjust.xib */; };
A6D1A26921855EF5006FF2C1 /* ViewControllerControlLayerSwitcherDemo.m in Sources */ = {isa = PBXBuildFile; fileRef = A6D1A26821855EF5006FF2C1 /* ViewControllerControlLayerSwitcherDemo.m */; };
A6F9C3F2218590E200369341 /* ViewControllerTestPresent.m in Sources */ = {isa = PBXBuildFile; fileRef = A6F9C3F1218590E200369341 /* ViewControllerTestPresent.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -357,6 +358,8 @@
A6D1A26121845F02006FF2C1 /* ViewController_Adjust.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ViewController_Adjust.xib; sourceTree = "<group>"; };
A6D1A26721855EF5006FF2C1 /* ViewControllerControlLayerSwitcherDemo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewControllerControlLayerSwitcherDemo.h; sourceTree = "<group>"; };
A6D1A26821855EF5006FF2C1 /* ViewControllerControlLayerSwitcherDemo.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewControllerControlLayerSwitcherDemo.m; sourceTree = "<group>"; };
A6F9C3F0218590E200369341 /* ViewControllerTestPresent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewControllerTestPresent.h; sourceTree = "<group>"; };
A6F9C3F1218590E200369341 /* ViewControllerTestPresent.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewControllerTestPresent.m; sourceTree = "<group>"; };
CAED6A87F45B68EF4FBAAD38 /* Pods-SJVideoPlayer.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SJVideoPlayer.release.xcconfig"; path = "Pods/Target Support Files/Pods-SJVideoPlayer/Pods-SJVideoPlayer.release.xcconfig"; sourceTree = "<group>"; };
D2D51F57491F1093AB14DA2B /* libPods-SJVideoPlayerTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-SJVideoPlayerTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
DDCE7D7F757328DEFBB8B4E7 /* Pods-SJVideoPlayer.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SJVideoPlayer.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SJVideoPlayer/Pods-SJVideoPlayer.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -427,6 +430,8 @@
children = (
77E8D7602179A0E700B025A7 /* ViewControllerTest.h */,
77E8D7612179A0E700B025A7 /* ViewControllerTest.m */,
A6F9C3F0218590E200369341 /* ViewControllerTestPresent.h */,
A6F9C3F1218590E200369341 /* ViewControllerTestPresent.m */,
);
path = Test;
sourceTree = "<group>";
Expand Down Expand Up @@ -1277,6 +1282,7 @@
A6006694216108880001B5F8 /* ViewControllerFitOnScreen.m in Sources */,
A600655F215F947E0001B5F8 /* AppDelegate.m in Sources */,
A6006627215F974B0001B5F8 /* SJVideoPlayerDraggingProgressView.m in Sources */,
A6F9C3F2218590E200369341 /* ViewControllerTestPresent.m in Sources */,
A6006644215F974B0001B5F8 /* SJFilmEditingRecordingView.m in Sources */,
A6D1A24A2183FBB9006FF2C1 /* SJLoadFailedControlLayer.m in Sources */,
A600666C216085C90001B5F8 /* SJPlayView.m in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "SJEdgeControlLayer.h"
#import "SJLoadFailedControlLayer.h"
#import <NSObject+SJObserverHelper.h>
#import "ViewControllerTestPresent.h"

@interface ViewControllerTest ()<SJRouteHandler, SJEdgeControlButtonItemDelegate>
@property (nonatomic, strong) SJVideoPlayer *player;
Expand All @@ -38,6 +39,7 @@ - (void)viewDidLoad {
self.edgesForExtendedLayout = UIRectEdgeNone;
self.view.backgroundColor = [UIColor whiteColor];


[self _setupViews];

[self _addControlLayerToSwitcher];
Expand Down Expand Up @@ -106,6 +108,9 @@ - (void)test {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.player.URLAsset = [[SJVideoPlayerURLAsset alloc] initWithURL:[NSURL URLWithString:@"http://www.tetet.com"]];
});

// [_player showTitle:@"3秒后测试充满屏幕的情况" duration:3];
// [self presentViewController:[ViewControllerTestPresent new] animated:YES completion:nil];
}

/// test
Expand All @@ -120,7 +125,7 @@ - (void)_setupViews {
[self.view addSubview:_player.view];
[_player.view mas_makeConstraints:^(MASConstraintMaker *make) {
if (@available(iOS 11.0, *)) make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
else make.top.offset(0);
else make.top.offset(20);
make.leading.trailing.offset(0);
make.height.equalTo(self->_player.view.mas_width).multipliedBy(9 / 16.0f);
}];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ViewControllerTestPresent.h
// SJVideoPlayer
//
// Created by 畅三江 on 2018/10/28.
// Copyright © 2018 畅三江. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface ViewControllerTestPresent : UIViewController

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// ViewControllerTestPresent.m
// SJVideoPlayer
//
// Created by 畅三江 on 2018/10/28.
// Copyright © 2018 畅三江. All rights reserved.
//

#import "ViewControllerTestPresent.h"
#import "SJVideoPlayer.h"
#import <Masonry/Masonry.h>

@interface ViewControllerTestPresent ()
@property (nonatomic, strong) SJVideoPlayer *player;
@end

@implementation ViewControllerTestPresent

- (void)viewDidLoad {
[super viewDidLoad];
self.edgesForExtendedLayout = UIRectEdgeNone;
self.view.backgroundColor = [UIColor whiteColor];

// create a player of the default type
_player = [SJVideoPlayer player];

[self.view addSubview:_player.view];
[_player.view mas_makeConstraints:^(MASConstraintMaker *make) {
// if (@available(iOS 11.0, *)) make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
// else make.top.offset(0);
// make.leading.trailing.offset(0);
// make.height.equalTo(self->_player.view.mas_width).multipliedBy(9 / 16.0f);
make.edges.offset(0);
}];

_player.URLAsset = [[SJVideoPlayerURLAsset alloc] initWithURL:[NSBundle.mainBundle URLForResource:@"play" withExtension:@"mp4"]];
_player.URLAsset.title = @"Test Title";
_player.URLAsset.alwaysShowTitle = YES;
_player.hideBackButtonWhenOrientationIsPortrait = YES;
_player.enableFilmEditing = YES;
_player.pausedToKeepAppearState = YES;
_player.generatePreviewImages = YES;

#pragma mark
UILabel *noteLabel = [UILabel new];
noteLabel.numberOfLines = 0;
noteLabel.text = @"This is a simple demo, please use other demos to understand how to use.\n此为简单Demo, 请通过其他Demo来了解如何使用.";
noteLabel.font = [UIFont systemFontOfSize:12];
[self.view addSubview:noteLabel];
[noteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.offset(8);
make.trailing.offset(-8);
make.centerY.offset(0);
}];
// Do any additional setup after loading the view.
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.player vc_viewDidAppear];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.player vc_viewWillDisappear];
}

- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self.player vc_viewDidDisappear];
}

- (BOOL)prefersStatusBarHidden {
return [self.player vc_prefersStatusBarHidden];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.player vc_preferredStatusBarStyle];
}

- (BOOL)prefersHomeIndicatorAutoHidden {
return YES;
}

@end

0 comments on commit 5c2b4d8

Please sign in to comment.