Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two bugs of PLSClipMovieView #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 43 additions & 13 deletions Example/PLShortVideoKitDemo/UI+Tools/PLSClipMovieView.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ - (void)setImageData:(UIImage *)imageData {

static NSString * const PLSClipMovieViewCellId = @"PLSClipMovieViewCellId";

@interface PLSClipMovieView () <UICollectionViewDataSource, UICollectionViewDelegate>
@interface PLSClipMovieView () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@property (strong, nonatomic) NSURL *url; // 视频的 url
@property (nonatomic, assign) Float64 frameRate; // 帧率
Expand Down Expand Up @@ -387,9 +387,18 @@ - (void)leftDragGesture:(UIPanGestureRecognizer *)ges {
return;
}

if (ges.view.x + translation.x <= maxX && ges.view.x + translation.x >= 0) {
// if (ges.view.x + translation.x <= maxX && ges.view.x + translation.x >= 0) {
if (ges.view.x + translation.x <= maxX) {

CGFloat distance;
if(ges.view.x + translation.x < 0){
distance = 0;
}else{
distance = ges.view.x + translation.x;
}

[ges.view mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(ges.view.x + translation.x);
make.left.mas_offset(distance);
}];

[ges setTranslation:CGPointZero inView:self];
Expand Down Expand Up @@ -439,8 +448,13 @@ - (void)rightDragGesture:(UIPanGestureRecognizer *)ges {
return;
}

if (CGRectGetMaxX(ges.view.frame) + translation.x >=minX && CGRectGetMaxX(ges.view.frame) + translation.x <= self.width) {
CGFloat distance = self.width - (CGRectGetMaxX(ges.view.frame) + translation.x);
if (CGRectGetMaxX(ges.view.frame) + translation.x >=minX) {
CGFloat distance;
if(CGRectGetMaxX(ges.view.frame) + translation.x > self.width){
distance = 0;
}else{
distance = self.width - (CGRectGetMaxX(ges.view.frame) + translation.x);
}
[ges.view mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.mas_offset(-distance);
}];
Expand Down Expand Up @@ -548,6 +562,25 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
return cell;
}

#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGFloat realImageCount = self.totalSeconds * PLSMinImageCount / self.maxDuration;
if(ceil(realImageCount) > PLSMinImageCount && realImageCount > 0 && indexPath.item == ceil(realImageCount) - 1){
CGFloat remain = realImageCount - floorf(realImageCount);
return CGSizeMake(CGRectGetWidth(self.frame) / PLSMinImageCount * remain, PLSImagesViewH);
}else{
return CGSizeMake(CGRectGetWidth(self.frame) / PLSMinImageCount, PLSImagesViewH);
}
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return CGFLOAT_MIN;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return CGFLOAT_MIN;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
if ([self.delegate respondsToSelector:@selector(didStartDragView)]) {
[self.delegate didStartDragView];
Expand Down Expand Up @@ -655,22 +688,19 @@ - (NSMutableArray *)collectionImages {

- (UICollectionView *)collectionView {
if (!_collectionView) {

UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.itemSize = CGSizeMake(PLSImagesVIewW, PLSImagesViewH);
layout.minimumLineSpacing = 0;
CGRect collectionRect = CGRectMake(0, 0, PLS_SCREEN_WIDTH, PLSImagesViewH);
_collectionView = [[UICollectionView alloc] initWithFrame:collectionRect collectionViewLayout:layout];
// layout.itemSize = CGSizeMake(PLSImagesVIewW, PLSImagesViewH);
// layout.minimumLineSpacing = 0;

// CGRect collectionRect = CGRectMake(0, 0, PLS_SCREEN_WIDTH, PLSImagesViewH);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.dataSource = self;
_collectionView.delegate = self;

[self.collectionView registerClass:[PLSClipMovieViewCell class] forCellWithReuseIdentifier:PLSClipMovieViewCellId];

_collectionView.showsHorizontalScrollIndicator = NO;
}

return _collectionView;
}

Expand Down