Commit b53c5298 authored by tanzhen's avatar tanzhen

新增视频预览功能

parent 5acab807
No preview for this file type
......@@ -32,7 +32,7 @@
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="显示内部拍照按钮" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="R92-Zn-NWV">
<rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
......@@ -47,7 +47,7 @@
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="照片按修改时间升序排列" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UL3-n3-Hmt">
<rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
......@@ -58,11 +58,14 @@
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="a58-aK-ZB0">
<rect key="frame" x="225" y="6" width="51" height="31"/>
<connections>
<action selector="allowPickingVideoSwitchClick:" destination="BYZ-38-t0r" eventType="valueChanged" id="kMA-4q-CZa"/>
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="允许选择视频" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xCu-D3-IZg">
<rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
......@@ -80,7 +83,7 @@
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="允许选择照片" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vNN-OI-9z1">
<rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
......@@ -98,7 +101,7 @@
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="允许选择照片原图" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7mi-Lf-2N5">
<rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
......@@ -116,7 +119,7 @@
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="把拍照按钮放在外面(未实现)" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jop-5R-ioj">
<rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
......
......@@ -115,6 +115,7 @@
_imageView = imageView;
[self.contentView bringSubviewToFront:_selectImageView];
[self.contentView bringSubviewToFront:_bottomView];
}
return _imageView;
}
......
......@@ -117,7 +117,7 @@
self = [super initWithRootViewController:previewVc];
if (self) {
self.selectedAssets = [NSMutableArray arrayWithArray:selectedAssets];
self.allowPickingOriginalPhoto = YES;
self.allowPickingOriginalPhoto = self.allowPickingOriginalPhoto;
self.timeout = 15;
self.photoWidth = 828.0;
self.maxImagesCount = selectedAssets.count;
......
......@@ -117,7 +117,11 @@
if (imagePickerVc.didFinishPickingVideoHandle) {
imagePickerVc.didFinishPickingVideoHandle(_cover,_model.asset);
}
if (self.navigationController) {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
} else {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
#pragma mark - Notification Method
......
......@@ -11,8 +11,10 @@
@interface TZTestCell : UICollectionViewCell
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIImageView *videoImageView;
@property (nonatomic, strong) UIButton *deleteBtn;
@property (nonatomic, assign) NSInteger row;
@property (nonatomic, strong) id asset;
- (UIView *)snapshotView;
......
......@@ -8,6 +8,9 @@
#import "TZTestCell.h"
#import "UIView+Layout.h"
#import <Photos/Photos.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import "TZImagePickerController/TZImagePickerController.h"
@implementation TZTestCell
......@@ -21,6 +24,12 @@
[self addSubview:_imageView];
self.clipsToBounds = YES;
_videoImageView = [[UIImageView alloc] init];
_videoImageView.image = [UIImage imageNamedFromMyBundle:@"MMVideoPreviewPlay"];
_videoImageView.contentMode = UIViewContentModeScaleAspectFill;
_videoImageView.hidden = YES;
[self addSubview:_videoImageView];
_deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_deleteBtn setImage:[UIImage imageNamed:@"photo_delete"] forState:UIControlStateNormal];
_deleteBtn.frame = CGRectMake(self.tz_width - 36, 0, 36, 36);
......@@ -34,8 +43,21 @@
- (void)layoutSubviews {
[super layoutSubviews];
_imageView.frame = self.bounds;
CGFloat width = self.tz_width / 3.0;
_videoImageView.frame = CGRectMake(width, width, width, width);
}
- (void)setAsset:(id)asset {
_asset = asset;
if ([asset isKindOfClass:[PHAsset class]]) {
PHAsset *phAsset = asset;
_videoImageView.hidden = phAsset.mediaType != PHAssetMediaTypeVideo;
} else if ([asset isKindOfClass:[ALAsset class]]) {
ALAsset *alAsset = asset;
_videoImageView.hidden = ![[alAsset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo];
}
}
- (void)setRow:(NSInteger)row {
_row = row;
_deleteBtn.tag = row;
......
......@@ -14,6 +14,7 @@
#import <Photos/Photos.h>
#import "LxGridViewFlowLayout.h"
#import "TZImageManager.h"
#import "TZVideoPlayerController.h"
@interface ViewController ()<TZImagePickerControllerDelegate,UICollectionViewDataSource,UICollectionViewDelegate> {
NSMutableArray *_selectedPhotos;
......@@ -70,11 +71,13 @@
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
TZTestCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZTestCell" forIndexPath:indexPath];
cell.videoImageView.hidden = YES;
if (indexPath.row == _selectedPhotos.count) {
cell.imageView.image = [UIImage imageNamed:@"AlbumAddBtn.png"];
cell.deleteBtn.hidden = YES;
} else {
cell.imageView.image = _selectedPhotos[indexPath.row];
cell.asset = _selectedAssets[indexPath.row];
cell.deleteBtn.hidden = NO;
}
cell.deleteBtn.tag = indexPath.row;
......@@ -85,10 +88,25 @@
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == _selectedPhotos.count) {
[self pushImagePickerController];
} else { // preview photos or video / 预览照片或者视频
id asset = _selectedAssets[indexPath.row];
BOOL isVideo = NO;
if ([asset isKindOfClass:[PHAsset class]]) {
PHAsset *phAsset = asset;
isVideo = phAsset.mediaType == PHAssetMediaTypeVideo;
} else if ([asset isKindOfClass:[ALAsset class]]) {
ALAsset *alAsset = asset;
isVideo = [[alAsset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo];
}
if (isVideo) { // perview video / 预览视频
TZVideoPlayerController *vc = [[TZVideoPlayerController alloc] init];
TZAssetModel *model = [TZAssetModel modelWithAsset:asset type:TZAssetModelMediaTypeVideo timeLength:@""];
vc.model = model;
[self presentViewController:vc animated:YES completion:nil];
} else { // preview photos / 预览照片
TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithSelectedAssets:_selectedAssets selectedPhotos:_selectedPhotos index:indexPath.row];
imagePickerVc.allowPickingOriginalPhoto = self.allowPickingOriginalPhotoSwitch.isOn;
imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
// imagePickerVc.allowPickingOriginalPhoto = NO;
[imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
_selectedPhotos = [NSMutableArray arrayWithArray:photos];
_selectedAssets = [NSMutableArray arrayWithArray:assets];
......@@ -99,6 +117,7 @@
}];
[self presentViewController:imagePickerVc animated:YES completion:nil];
}
}
}
- (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)sourceIndexPath didMoveToIndexPath:(NSIndexPath *)destinationIndexPath {
......@@ -143,6 +162,7 @@
}];
[self presentViewController:imagePickerVc animated:YES completion:nil];
}
......@@ -184,6 +204,13 @@
if (!sender.isOn) {
[_allowPickingOriginalPhotoSwitch setOn:NO animated:YES];
[_showTakePhotoBtnSwitch setOn:NO animated:YES];
[_allowPickingVideoSwitch setOn:YES animated:YES];
}
}
- (IBAction)allowPickingVideoSwitchClick:(UISwitch *)sender {
if (!sender.isOn) {
[_allowPickingImageSwitch setOn:YES animated:YES];
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment