Skip to content

Commit

Permalink
完善新版控制层在处理点击手势时的处理
Browse files Browse the repository at this point in the history
  • Loading branch information
changsanjiang committed Nov 6, 2018
1 parent 5d1b0d4 commit ee4b0e2
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 34 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.1.1'
s.version = '2.2.2'
s.summary = 'video player.'
s.description = 'https://github.com/changsanjiang/SJVideoPlayer/blob/master/README.md'
s.homepage = 'https://github.com/changsanjiang/SJVideoPlayer'
Expand Down
2 changes: 2 additions & 0 deletions SJVideoPlayer/Adapters/Core/SJEdgeControlLayerItemAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
- (NSInteger)indexOfItemForTag:(SJEdgeControlButtonItemTag)tag;
- (nullable NSArray<SJEdgeControlButtonItem *> *)itemsWithRange:(NSRange)range;
- (BOOL)itemsIsHiddenWithRange:(NSRange)range; // 此范围的items是否已隐藏
- (BOOL)itemContainsPoint:(CGPoint)point; // 某个点是否在item中

/// 添加
/// - 注意: 添加后, 记得调用刷新
Expand All @@ -47,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)exchangeItemAtIndex:(NSInteger)idx1 withItemAtIndex:(NSInteger)idx2;
- (void)exchangeItemForTag:(SJEdgeControlButtonItemTag)tag1 withItemForTag:(SJEdgeControlButtonItemTag)tag2;


@property (nonatomic, strong, readonly) UIView *view;
@property (nonatomic, readonly) NSInteger itemCount;
- (instancetype)init NS_UNAVAILABLE;
Expand Down
9 changes: 8 additions & 1 deletion SJVideoPlayer/Adapters/Core/SJEdgeControlLayerItemAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ @interface SJCollectionViewLayout : UICollectionViewLayout
@end

@implementation SJCollectionViewLayout {
@private NSMutableArray<UICollectionViewLayoutAttributes *> *_layoutAttributes;
@public NSMutableArray<UICollectionViewLayoutAttributes *> *_layoutAttributes;
}
- (instancetype)init {
self = [super init];
Expand Down Expand Up @@ -284,6 +284,13 @@ - (BOOL)itemsIsHiddenWithRange:(NSRange)range {
}
return YES;
}
- (BOOL)itemContainsPoint:(CGPoint)point {
for ( UICollectionViewLayoutAttributes *atr in _layout->_layoutAttributes ) {
if ( CGRectContainsPoint(atr.frame, point) )
return YES;
}
return NO;
}

#pragma mark -
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
Expand Down
49 changes: 43 additions & 6 deletions SJVideoPlayer/SJEdgeControlLayer/SJEdgeControlLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ - (BOOL)_canDisappearFor_TopAdapter {
return YES;
}

- (BOOL)_canTriggerGesturesFor_TopAdapter:(CGPoint)location {
if ( CGRectContainsPoint(_topAdapter.view.frame, location) &&
[_topAdapter itemContainsPoint:[self.controlView convertPoint:location toView:_topAdapter.view]] )
return NO;

return YES;
}

- (void)clickedBackItem:(SJEdgeControlButtonItem *)item {
if ( _videoPlayer.useFitOnScreenAndDisableRotation ) {
if ( _videoPlayer.isFitOnScreen ) {
Expand Down Expand Up @@ -397,6 +405,14 @@ - (BOOL)_canDisappearFor_LeftAdapter {
return YES;
}

- (BOOL)_canTriggerGesturesFor_LeftAdapter:(CGPoint)location {
if ( CGRectContainsPoint(_leftAdapter.view.frame, location) &&
[_leftAdapter itemContainsPoint:[self.controlView convertPoint:location toView:_leftAdapter.view]] )
return NO;

return YES;
}

/// item actions
- (void)clickedLockItem:(SJEdgeControlButtonItem *)item {
self.videoPlayer.lockedScreen = !self.videoPlayer.isLockedScreen;
Expand Down Expand Up @@ -578,6 +594,14 @@ - (BOOL)_canDisappearFor_BottomAdapter {
return !slider.isDragging;
}

- (BOOL)_canTriggerGesturesFor_BottomAdapter:(CGPoint)location {
if ( CGRectContainsPoint(_bottomAdapter.view.frame, location) &&
[_bottomAdapter itemContainsPoint:[self.controlView convertPoint:location toView:_bottomAdapter.view]] )
return NO;

return YES;
}

- (void)clickedPlayItem:(SJEdgeControlButtonItem *)item {
if ( [self.videoPlayer playStatus_isPlaying] ) [self.videoPlayer pause];
else [self.videoPlayer play];
Expand Down Expand Up @@ -651,6 +675,13 @@ - (BOOL)_canDisapearFor_RightAdapter {
return YES;
}

- (BOOL)_canTriggerGesturesFor_RightAdapter:(CGPoint)location {
if ( CGRectContainsPoint(_rightAdapter.view.frame, location) &&
[_rightAdapter itemContainsPoint:[self.controlView convertPoint:location toView:_rightAdapter.view]] )
return NO;

return YES;
}

#pragma mark - center
@synthesize replayButton = _replayButton;
Expand Down Expand Up @@ -725,7 +756,7 @@ - (SJLoadingView *)loadingView {
- (SJVideoPlayerDraggingProgressView *)draggingProgressView {
if ( _draggingProgressView ) return _draggingProgressView;
_draggingProgressView = [SJVideoPlayerDraggingProgressView new];
[_draggingProgressView setPreviewImage:_videoPlayer.placeholder];
[_draggingProgressView setPreviewImage:_videoPlayer.placeholderImageView.image];
[self.controlView addSubview:_draggingProgressView];
[self _hidden:_draggingProgressView animated:NO];
[_draggingProgressView mas_makeConstraints:^(MASConstraintMaker *make) {
Expand Down Expand Up @@ -787,15 +818,21 @@ - (UIView *)controlView {
return self;
}

/// 是否可以触发播放器的手势
- (BOOL)triggerGesturesCondition:(CGPoint)location {
if ( CGRectContainsPoint( _topContainerView.frame, location ) ||
CGRectContainsPoint( _leftContainerView.frame, location ) ||
CGRectContainsPoint( _bottomContainerView.frame, location ) ||
CGRectContainsPoint( _rightContainerView.frame, location ) ||
CGRectContainsPoint( _previewView.frame, location) ) return NO;
if ( ![self _canTriggerGesturesFor_TopAdapter:location] ||
![self _canTriggerGesturesFor_LeftAdapter:location] ||
![self _canTriggerGesturesFor_BottomAdapter:location] ||
![self _canTriggerGesturesFor_RightAdapter:location] ) return NO;

if ( CGRectContainsPoint( _previewView.frame, location) )
return NO;

return YES;
}

/// 当播放器尝试自动隐藏控制层时, 将会调用这个方法
/// - 返回Yes, 将隐藏控制层
- (BOOL)controlLayerDisappearCondition {
if ( [self _canDisappearFor_BottomAdapter] &&
[self _canDisappearFor_LeftAdapter] &&
Expand Down
9 changes: 7 additions & 2 deletions SJVideoPlayer/SJVideoPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,17 @@ - (instancetype)_init {
_recorder = [[SJVideoPlayerControlSettingRecorder alloc] initWithSettings:^(SJEdgeControlLayerSettings * _Nonnull setting) {
__strong typeof(_self) self = _self;
if ( !self ) return ;
if ( [SJVideoPlayerSettings commonSettings].placeholder ) self.placeholder = [SJVideoPlayerSettings commonSettings].placeholder;
[self _updateCommonProperties];
}];
self.placeholder = [SJVideoPlayerSettings commonSettings].placeholder;
[self _updateCommonProperties];
return self;
}

- (void)_updateCommonProperties {
if ( self.placeholderImageView.image != SJVideoPlayerSettings.commonSettings.placeholder )
self.placeholderImageView.image = SJVideoPlayerSettings.commonSettings.placeholder;
}

@synthesize switcher = _switcher;
- (SJControlLayerSwitcher *)switcher {
if ( _switcher ) return _switcher;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

0 comments on commit ee4b0e2

Please sign in to comment.