From afa4c5dba1cadb047f333315854bc573f47bd282 Mon Sep 17 00:00:00 2001 From: zjmdp Date: Fri, 1 Sep 2017 15:31:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DPLSClipMovieView=E7=9A=84?= =?UTF-8?q?cut=20bar=E6=9C=89=E6=97=B6=E5=80=99=E6=97=A0=E6=B3=95=E9=9D=A0?= =?UTF-8?q?=E8=BE=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI+Tools/PLSClipMovieView.m | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Example/PLShortVideoKitDemo/UI+Tools/PLSClipMovieView.m b/Example/PLShortVideoKitDemo/UI+Tools/PLSClipMovieView.m index 34b8fe56..67544d1c 100644 --- a/Example/PLShortVideoKitDemo/UI+Tools/PLSClipMovieView.m +++ b/Example/PLShortVideoKitDemo/UI+Tools/PLSClipMovieView.m @@ -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]; @@ -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); }]; From f41635e6d77e788e3e62c97d472360d072081f0b Mon Sep 17 00:00:00 2001 From: zjmdp Date: Fri, 1 Sep 2017 15:35:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DPLSClipMovieView=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=BD=B4=E9=94=99=E8=AF=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI+Tools/PLSClipMovieView.m | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Example/PLShortVideoKitDemo/UI+Tools/PLSClipMovieView.m b/Example/PLShortVideoKitDemo/UI+Tools/PLSClipMovieView.m index 67544d1c..64ffab7f 100644 --- a/Example/PLShortVideoKitDemo/UI+Tools/PLSClipMovieView.m +++ b/Example/PLShortVideoKitDemo/UI+Tools/PLSClipMovieView.m @@ -137,7 +137,7 @@ - (void)setImageData:(UIImage *)imageData { static NSString * const PLSClipMovieViewCellId = @"PLSClipMovieViewCellId"; -@interface PLSClipMovieView () +@interface PLSClipMovieView () @property (strong, nonatomic) NSURL *url; // 视频的 url @property (nonatomic, assign) Float64 frameRate; // 帧率 @@ -562,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]; @@ -669,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; }