Commit 85dd912f authored by banchichen's avatar banchichen
parents 19724816 d7783ad2
No preview for this file type
...@@ -42,8 +42,15 @@ ...@@ -42,8 +42,15 @@
2016.5.23更新: 2016.5.23更新:
刚刚更新了代码,现在版本更新到了1.4.0,新增了一些新功能,比如:在照片列表页新增了拍照按钮,可以全局记录哪个相册已选中了多少张图片,预览控制器可以在外界打开。同时Demo页面也做了一些优化,可以直接删除选中的照片、可以对照片进行长按排序等。当然期间也修复了许多小bug,表现更加好了。 刚刚更新了代码,现在版本更新到了1.4.5,新增了一些新功能,比如:在照片列表页新增了拍照按钮,可以全局记录哪个相册已选中了多少张图片,预览控制器可以在外界打开。同时Demo页面也做了一些优化,可以直接删除选中的照片、可以对照片进行长按排序等。当然期间也修复了许多小bug,表现更加好了。
最值得一提的是,1.4.0版本的性能大幅提升了,在我的iOS9.3.2系统6s设备上(870张照片),平均滑动帧数在58左右,滑动十分流畅,在iOS7.0.4的4s设备上(124张照片),平均滑动帧数在57左右,也十分流畅。经过对比,和QQ的图片选择器滑动帧数表现基本一致,都十分流畅,同时都强于微信的图片选择器。微信的图片选择器,在快速滑动的时候明显感到有一丝卡顿,通过Core Animation查看发现,微信的图片选择器在我的6s设备下帧数平均约52左右,好几次甚至低于50,在4s设备上则表现更糟一些。下面贴上帧数测试截图,大家也可以测试一下~(测试截图请去博客查看~) 最值得一提的是,1.4.5版本的性能大幅提升了,在我的iOS9.3.2系统6s设备上(870张照片),平均滑动帧数在58左右,滑动十分流畅,在iOS7.0.4的4s设备上(124张照片),平均滑动帧数在57左右,也十分流畅。经过对比,和QQ的图片选择器滑动帧数表现基本一致,都十分流畅,同时都强于微信的图片选择器。微信的图片选择器,在快速滑动的时候明显感到有一丝卡顿,通过Core Animation查看发现,微信的图片选择器在我的6s设备下帧数平均约52左右,好几次甚至低于50,在4s设备上则表现更糟一些。下面贴上帧数测试截图,大家也可以测试一下~(测试截图请去博客查看~)
tip: 如果你用的是老版本,建议你更新到新版,特别是需要适配iOS7甚至6的应用,因为旧版本在iOS7和6下性能比较糟糕... tip: 如果你用的是老版本,建议你更新到新版,特别是需要适配iOS7甚至6的应用,因为旧版本在iOS7和6下性能比较糟糕...
2016.6.22更新:
刚刚更新了代码,现在版本更新到了1.5.0。更新如下:
1.可把拍照按钮放在外面了,可以设置弹出一个sheet提示用户选择相册或相机;
2.新增了sortAscendingByModificationDate属性,默认为YES,设置为NO时,照片会按修改时间降序,拍照按钮会在第一个;
3.优化了Demo页面的UI,新增6个开关控件,可方便地更改各个设置来打开选择器;
4.修复了若干bug;
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "TZImagePickerController" s.name = "TZImagePickerController"
s.version = "1.4.5" s.version = "1.5.0"
s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video" s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video"
s.homepage = "https://github.com/banchichen/TZImagePickerController" s.homepage = "https://github.com/banchichen/TZImagePickerController"
s.license = "MIT" s.license = "MIT"
s.author = { "banchichen" => "736420282@qq.com" } s.author = { "banchichen" => "736420282@qq.com" }
s.platform = :ios s.platform = :ios
s.ios.deployment_target = "6.0" s.ios.deployment_target = "6.0"
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.4.5" } s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.5.0" }
s.requires_arc = true s.requires_arc = true
s.resources = "TZImagePickerController/TZImagePickerController/*.{png,xib,nib,bundle}" s.resources = "TZImagePickerController/TZImagePickerController/*.{png,xib,nib,bundle}"
s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}" s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}"
......
...@@ -32,7 +32,7 @@ ...@@ -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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/> <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"/> <nil key="highlightedColor"/>
</label> </label>
</subviews> </subviews>
...@@ -47,7 +47,7 @@ ...@@ -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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/> <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"/> <nil key="highlightedColor"/>
</label> </label>
</subviews> </subviews>
...@@ -58,11 +58,14 @@ ...@@ -58,11 +58,14 @@
<subviews> <subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="a58-aK-ZB0"> <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"/> <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> </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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/> <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"/> <nil key="highlightedColor"/>
</label> </label>
</subviews> </subviews>
...@@ -80,7 +83,7 @@ ...@@ -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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/> <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"/> <nil key="highlightedColor"/>
</label> </label>
</subviews> </subviews>
...@@ -98,7 +101,7 @@ ...@@ -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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/> <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"/> <nil key="highlightedColor"/>
</label> </label>
</subviews> </subviews>
...@@ -110,13 +113,13 @@ ...@@ -110,13 +113,13 @@
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="uHt-bT-lBZ"> <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="uHt-bT-lBZ">
<rect key="frame" x="225" y="6" width="51" height="31"/> <rect key="frame" x="225" y="6" width="51" height="31"/>
<connections> <connections>
<action selector="showSheetSwitchClick:" destination="BYZ-38-t0r" eventType="valueChanged" id="sRv-xW-VSh"/> <action selector="showSheetSwitchClick:" destination="BYZ-38-t0r" eventType="valueChanged" id="kmV-vK-SDz"/>
</connections> </connections>
</switch> </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="jop-5R-ioj"> <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"/> <rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/> <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"/> <nil key="highlightedColor"/>
</label> </label>
</subviews> </subviews>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.4.5</string> <string>1.5.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -115,6 +115,7 @@ ...@@ -115,6 +115,7 @@
_imageView = imageView; _imageView = imageView;
[self.contentView bringSubviewToFront:_selectImageView]; [self.contentView bringSubviewToFront:_selectImageView];
[self.contentView bringSubviewToFront:_bottomView];
} }
return _imageView; return _imageView;
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// //
// Created by 谭真 on 15/12/24. // Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved. // Copyright © 2015年 谭真. All rights reserved.
// version 1.4.5 // version 1.5.0
/* /*
经过测试,比起xib的方式,把TZAssetCell改用纯代码的方式来写,滑动帧数明显提高了(约提高10帧左右) 经过测试,比起xib的方式,把TZAssetCell改用纯代码的方式来写,滑动帧数明显提高了(约提高10帧左右)
......
...@@ -117,7 +117,7 @@ ...@@ -117,7 +117,7 @@
self = [super initWithRootViewController:previewVc]; self = [super initWithRootViewController:previewVc];
if (self) { if (self) {
self.selectedAssets = [NSMutableArray arrayWithArray:selectedAssets]; self.selectedAssets = [NSMutableArray arrayWithArray:selectedAssets];
self.allowPickingOriginalPhoto = YES; self.allowPickingOriginalPhoto = self.allowPickingOriginalPhoto;
self.timeout = 15; self.timeout = 15;
self.photoWidth = 828.0; self.photoWidth = 828.0;
self.maxImagesCount = selectedAssets.count; self.maxImagesCount = selectedAssets.count;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#import "TZImageManager.h" #import "TZImageManager.h"
#import "TZVideoPlayerController.h" #import "TZVideoPlayerController.h"
@interface TZPhotoPickerController ()<UICollectionViewDataSource,UICollectionViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate> { @interface TZPhotoPickerController ()<UICollectionViewDataSource,UICollectionViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIAlertViewDelegate> {
NSMutableArray *_models; NSMutableArray *_models;
UIButton *_previewButton; UIButton *_previewButton;
...@@ -357,10 +357,10 @@ static CGSize AssetGridThumbnailSize; ...@@ -357,10 +357,10 @@ static CGSize AssetGridThumbnailSize;
} }
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
// take a picture / 去拍照 // take a photo / 去拍照
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (((tzImagePickerVc.sortAscendingByModificationDate && indexPath.row >= _models.count) || (!tzImagePickerVc.sortAscendingByModificationDate && indexPath.row == 0)) && _showTakePhotoBtn) { if (((tzImagePickerVc.sortAscendingByModificationDate && indexPath.row >= _models.count) || (!tzImagePickerVc.sortAscendingByModificationDate && indexPath.row == 0)) && _showTakePhotoBtn) {
[self takePicture]; return; [self takePhoto]; return;
} }
// preview phote or video / 预览照片或视频 // preview phote or video / 预览照片或视频
NSInteger index = indexPath.row; NSInteger index = indexPath.row;
...@@ -395,16 +395,23 @@ static CGSize AssetGridThumbnailSize; ...@@ -395,16 +395,23 @@ static CGSize AssetGridThumbnailSize;
#pragma mark - Private Method #pragma mark - Private Method
- (void)takePicture { - (void)takePhoto {
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { if ((authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied) && iOS8Later) {
self.imagePickerVc.sourceType = sourceType; // 无权限 做一个友好的提示
if(iOS8Later) { UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法使用相机" message:@"请在iPhone的""设置-隐私-相机""中允许访问相机" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil];
_imagePickerVc.modalPresentationStyle = UIModalPresentationOverCurrentContext; [alert show];
} else { // 调用相机
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
self.imagePickerVc.sourceType = sourceType;
if(iOS8Later) {
_imagePickerVc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
}
[self presentViewController:_imagePickerVc animated:YES completion:nil];
} else {
NSLog(@"模拟器中无法打开照相机,请在真机中使用");
} }
[self presentViewController:_imagePickerVc animated:YES completion:nil];
} else {
NSLog(@"模拟器中无法打开照相机,请在真机中使用");
} }
} }
...@@ -487,6 +494,18 @@ static CGSize AssetGridThumbnailSize; ...@@ -487,6 +494,18 @@ static CGSize AssetGridThumbnailSize;
} }
} }
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) { // 去设置界面,开启相机访问权限
if (iOS8Later) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
} else {
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=Photos"]];
}
}
}
#pragma mark - UIImagePickerControllerDelegate #pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
......
...@@ -117,7 +117,11 @@ ...@@ -117,7 +117,11 @@
if (imagePickerVc.didFinishPickingVideoHandle) { if (imagePickerVc.didFinishPickingVideoHandle) {
imagePickerVc.didFinishPickingVideoHandle(_cover,_model.asset); imagePickerVc.didFinishPickingVideoHandle(_cover,_model.asset);
} }
[self.navigationController dismissViewControllerAnimated:YES completion:nil]; if (self.navigationController) {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
} else {
[self dismissViewControllerAnimated:YES completion:nil];
}
} }
#pragma mark - Notification Method #pragma mark - Notification Method
......
...@@ -11,8 +11,10 @@ ...@@ -11,8 +11,10 @@
@interface TZTestCell : UICollectionViewCell @interface TZTestCell : UICollectionViewCell
@property (nonatomic, strong) UIImageView *imageView; @property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIImageView *videoImageView;
@property (nonatomic, strong) UIButton *deleteBtn; @property (nonatomic, strong) UIButton *deleteBtn;
@property (nonatomic, assign) NSInteger row; @property (nonatomic, assign) NSInteger row;
@property (nonatomic, strong) id asset;
- (UIView *)snapshotView; - (UIView *)snapshotView;
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#import "TZTestCell.h" #import "TZTestCell.h"
#import "UIView+Layout.h" #import "UIView+Layout.h"
#import <Photos/Photos.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import "TZImagePickerController/TZImagePickerController.h"
@implementation TZTestCell @implementation TZTestCell
...@@ -21,6 +24,12 @@ ...@@ -21,6 +24,12 @@
[self addSubview:_imageView]; [self addSubview:_imageView];
self.clipsToBounds = YES; 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 = [UIButton buttonWithType:UIButtonTypeCustom];
[_deleteBtn setImage:[UIImage imageNamed:@"photo_delete"] forState:UIControlStateNormal]; [_deleteBtn setImage:[UIImage imageNamed:@"photo_delete"] forState:UIControlStateNormal];
_deleteBtn.frame = CGRectMake(self.tz_width - 36, 0, 36, 36); _deleteBtn.frame = CGRectMake(self.tz_width - 36, 0, 36, 36);
...@@ -34,8 +43,21 @@ ...@@ -34,8 +43,21 @@
- (void)layoutSubviews { - (void)layoutSubviews {
[super layoutSubviews]; [super layoutSubviews];
_imageView.frame = self.bounds; _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 { - (void)setRow:(NSInteger)row {
_row = row; _row = row;
_deleteBtn.tag = row; _deleteBtn.tag = row;
......
This diff is collapsed.
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