Commit d7bf525e authored by banchichen's avatar banchichen

1.7.3版本 主要优化了iCloud图片的显示与选择

parent 55f0f42c
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "TZImagePickerController" s.name = "TZImagePickerController"
s.version = "1.7.2" s.version = "1.7.3"
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" => "tanzhenios@foxmail.com" } s.author = { "banchichen" => "tanzhenios@foxmail.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.7.2" } s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.7.3" }
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}"
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
6D5358CD1D64600F00928CC6 /* NSBundle+TZImagePicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D5358CC1D64600F00928CC6 /* NSBundle+TZImagePicker.m */; }; 6D5358CD1D64600F00928CC6 /* NSBundle+TZImagePicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D5358CC1D64600F00928CC6 /* NSBundle+TZImagePicker.m */; };
6DC358661CC8BAFD00898D29 /* TZImagePickerController.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 6DC358651CC8BAFD00898D29 /* TZImagePickerController.bundle */; }; 6DC358661CC8BAFD00898D29 /* TZImagePickerController.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 6DC358651CC8BAFD00898D29 /* TZImagePickerController.bundle */; };
6DC84D0A1DF5358500A107A9 /* TZImageCropManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6DC84D091DF5358500A107A9 /* TZImageCropManager.m */; }; 6DC84D0A1DF5358500A107A9 /* TZImageCropManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6DC84D091DF5358500A107A9 /* TZImageCropManager.m */; };
6DD0502B1DF659ED0057C78D /* TZProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6DD0502A1DF659ED0057C78D /* TZProgressView.m */; };
900E65811C2BB8D5003D9A9E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 900E65801C2BB8D5003D9A9E /* main.m */; }; 900E65811C2BB8D5003D9A9E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 900E65801C2BB8D5003D9A9E /* main.m */; };
900E65841C2BB8D5003D9A9E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 900E65831C2BB8D5003D9A9E /* AppDelegate.m */; }; 900E65841C2BB8D5003D9A9E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 900E65831C2BB8D5003D9A9E /* AppDelegate.m */; };
900E65871C2BB8D5003D9A9E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 900E65861C2BB8D5003D9A9E /* ViewController.m */; }; 900E65871C2BB8D5003D9A9E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 900E65861C2BB8D5003D9A9E /* ViewController.m */; };
...@@ -58,6 +59,8 @@ ...@@ -58,6 +59,8 @@
6DC358651CC8BAFD00898D29 /* TZImagePickerController.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = TZImagePickerController.bundle; sourceTree = "<group>"; }; 6DC358651CC8BAFD00898D29 /* TZImagePickerController.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = TZImagePickerController.bundle; sourceTree = "<group>"; };
6DC84D081DF5358500A107A9 /* TZImageCropManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TZImageCropManager.h; sourceTree = "<group>"; }; 6DC84D081DF5358500A107A9 /* TZImageCropManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TZImageCropManager.h; sourceTree = "<group>"; };
6DC84D091DF5358500A107A9 /* TZImageCropManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TZImageCropManager.m; sourceTree = "<group>"; }; 6DC84D091DF5358500A107A9 /* TZImageCropManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TZImageCropManager.m; sourceTree = "<group>"; };
6DD050291DF659ED0057C78D /* TZProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TZProgressView.h; sourceTree = "<group>"; };
6DD0502A1DF659ED0057C78D /* TZProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TZProgressView.m; sourceTree = "<group>"; };
900E657C1C2BB8D5003D9A9E /* TZImagePickerController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TZImagePickerController.app; sourceTree = BUILT_PRODUCTS_DIR; }; 900E657C1C2BB8D5003D9A9E /* TZImagePickerController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TZImagePickerController.app; sourceTree = BUILT_PRODUCTS_DIR; };
900E65801C2BB8D5003D9A9E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; 900E65801C2BB8D5003D9A9E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
900E65821C2BB8D5003D9A9E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; }; 900E65821C2BB8D5003D9A9E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
...@@ -213,6 +216,8 @@ ...@@ -213,6 +216,8 @@
900EF0141C2C134900EA709B /* TZPhotoPreviewCell.m */, 900EF0141C2C134900EA709B /* TZPhotoPreviewCell.m */,
90CE84B51C3BABB6003D0779 /* TZVideoPlayerController.h */, 90CE84B51C3BABB6003D0779 /* TZVideoPlayerController.h */,
90CE84B61C3BABB6003D0779 /* TZVideoPlayerController.m */, 90CE84B61C3BABB6003D0779 /* TZVideoPlayerController.m */,
6DD050291DF659ED0057C78D /* TZProgressView.h */,
6DD0502A1DF659ED0057C78D /* TZProgressView.m */,
90CE84AC1C3A89EF003D0779 /* TZImageManager.h */, 90CE84AC1C3A89EF003D0779 /* TZImageManager.h */,
90CE84AD1C3A89EF003D0779 /* TZImageManager.m */, 90CE84AD1C3A89EF003D0779 /* TZImageManager.m */,
6DC84D081DF5358500A107A9 /* TZImageCropManager.h */, 6DC84D081DF5358500A107A9 /* TZImageCropManager.h */,
...@@ -364,6 +369,7 @@ ...@@ -364,6 +369,7 @@
90EBF5D61C2E298000CB9BCC /* UIView+Layout.m in Sources */, 90EBF5D61C2E298000CB9BCC /* UIView+Layout.m in Sources */,
90CE84B71C3BABB6003D0779 /* TZVideoPlayerController.m in Sources */, 90CE84B71C3BABB6003D0779 /* TZVideoPlayerController.m in Sources */,
900EF0021C2BD7E400EA709B /* TZAssetCell.m in Sources */, 900EF0021C2BD7E400EA709B /* TZAssetCell.m in Sources */,
6DD0502B1DF659ED0057C78D /* TZProgressView.m in Sources */,
6D32B9BD1CD83640005CE1E0 /* LxGridViewFlowLayout.m in Sources */, 6D32B9BD1CD83640005CE1E0 /* LxGridViewFlowLayout.m in Sources */,
900EF0161C2C134900EA709B /* TZPhotoPreviewCell.m in Sources */, 900EF0161C2C134900EA709B /* TZPhotoPreviewCell.m in Sources */,
900E65871C2BB8D5003D9A9E /* ViewController.m in Sources */, 900E65871C2BB8D5003D9A9E /* ViewController.m in Sources */,
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.7.2</string> <string>1.7.3</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array> </array>
<key>UIViewControllerBasedStatusBarAppearance</key> <key>UIViewControllerBasedStatusBarAppearance</key>
<false/> <false/>
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "UIView+Layout.h" #import "UIView+Layout.h"
#import "TZImageManager.h" #import "TZImageManager.h"
#import "TZImagePickerController.h" #import "TZImagePickerController.h"
#import "TZProgressView.h"
@interface TZAssetCell () @interface TZAssetCell ()
@property (weak, nonatomic) UIImageView *imageView; // The photo / 照片 @property (weak, nonatomic) UIImageView *imageView; // The photo / 照片
...@@ -19,26 +20,22 @@ ...@@ -19,26 +20,22 @@
@property (weak, nonatomic) UILabel *timeLength; @property (weak, nonatomic) UILabel *timeLength;
@property (nonatomic, weak) UIImageView *viewImgView; @property (nonatomic, weak) UIImageView *viewImgView;
@property (nonatomic, strong) TZProgressView *progressView;
@property (nonatomic, assign) PHImageRequestID bigImageRequestID;
@end @end
@implementation TZAssetCell @implementation TZAssetCell
// Now we use code to create subViews for improve performance
// 现在我们用代码来创建TZAssetCell和TZAlbumCell的子控件,以提高性能
/*
- (void)awakeFromNib {
self.timeLength.font = [UIFont boldSystemFontOfSize:11];
}
*/
- (void)setModel:(TZAssetModel *)model { - (void)setModel:(TZAssetModel *)model {
_model = model; _model = model;
if (iOS8Later) { if (iOS8Later) {
self.representedAssetIdentifier = [[TZImageManager manager] getAssetIdentifier:model.asset]; self.representedAssetIdentifier = [[TZImageManager manager] getAssetIdentifier:model.asset];
} }
PHImageRequestID imageRequestID = [[TZImageManager manager] getPhotoWithAsset:model.asset photoWidth:self.tz_width completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) { PHImageRequestID imageRequestID = [[TZImageManager manager] getPhotoWithAsset:model.asset photoWidth:self.tz_width completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
if (_progressView) {
self.progressView.hidden = YES;
self.imageView.alpha = 1.0;
}
// Set the cell's thumbnail image if it's still showing the same asset. // Set the cell's thumbnail image if it's still showing the same asset.
if (!iOS8Later) { if (!iOS8Later) {
self.imageView.image = photo; return; self.imageView.image = photo; return;
...@@ -52,7 +49,7 @@ ...@@ -52,7 +49,7 @@
if (!isDegraded) { if (!isDegraded) {
self.imageRequestID = 0; self.imageRequestID = 0;
} }
}]; } progressHandler:nil networkAccessAllowed:NO];
if (imageRequestID && self.imageRequestID && imageRequestID != self.imageRequestID) { if (imageRequestID && self.imageRequestID && imageRequestID != self.imageRequestID) {
[[PHImageManager defaultManager] cancelImageRequest:self.imageRequestID]; [[PHImageManager defaultManager] cancelImageRequest:self.imageRequestID];
// NSLog(@"cancelImageRequest %d",self.imageRequestID); // NSLog(@"cancelImageRequest %d",self.imageRequestID);
...@@ -75,6 +72,10 @@ ...@@ -75,6 +72,10 @@
_selectImageView.hidden = YES; _selectImageView.hidden = YES;
} }
} }
// 如果用户选中了该图片,提前获取一下大图
if (model.isSelected) {
[self fetchBigImage];
}
} }
- (void)setShowSelectBtn:(BOOL)showSelectBtn { - (void)setShowSelectBtn:(BOOL)showSelectBtn {
...@@ -107,10 +108,40 @@ ...@@ -107,10 +108,40 @@
self.selectImageView.image = sender.isSelected ? [UIImage imageNamedFromMyBundle:self.photoSelImageName] : [UIImage imageNamedFromMyBundle:self.photoDefImageName]; self.selectImageView.image = sender.isSelected ? [UIImage imageNamedFromMyBundle:self.photoSelImageName] : [UIImage imageNamedFromMyBundle:self.photoDefImageName];
if (sender.isSelected) { if (sender.isSelected) {
[UIView showOscillatoryAnimationWithLayer:_selectImageView.layer type:TZOscillatoryAnimationToBigger]; [UIView showOscillatoryAnimationWithLayer:_selectImageView.layer type:TZOscillatoryAnimationToBigger];
// 用户选中了该图片,提前获取一下大图
[self fetchBigImage];
} else { // 取消选中,取消大图的获取
if (_bigImageRequestID && _progressView) {
[[PHImageManager defaultManager] cancelImageRequest:_bigImageRequestID];
[self hideProgressView];
}
} }
} }
#pragma mark - Lazy load - (void)hideProgressView {
self.progressView.hidden = YES;
self.imageView.alpha = 1.0;
}
- (void)fetchBigImage {
_bigImageRequestID = [[TZImageManager manager] getPhotoWithAsset:_model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
if (_progressView) {
[self hideProgressView];
}
} progressHandler:^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
if (_model.isSelected) {
progress = progress > 0.02 ? progress : 0.02;;
self.progressView.progress = progress;
self.progressView.hidden = NO;
self.imageView.alpha = 0.4;
} else {
*stop = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
} networkAccessAllowed:YES];
}
#pragma mark - Lazy load
- (UIButton *)selectPhotoButton { - (UIButton *)selectPhotoButton {
if (_selectImageView == nil) { if (_selectImageView == nil) {
...@@ -184,6 +215,18 @@ ...@@ -184,6 +215,18 @@
return _timeLength; return _timeLength;
} }
- (TZProgressView *)progressView {
if (_progressView == nil) {
_progressView = [[TZProgressView alloc] init];
static CGFloat progressWH = 20;
CGFloat progressXY = (self.tz_width - progressWH) / 2;
_progressView.hidden = YES;
_progressView.frame = CGRectMake(progressXY, progressXY, progressWH, progressWH);
[self addSubview:_progressView];
}
return _progressView;
}
@end @end
@interface TZAlbumCell () @interface TZAlbumCell ()
...@@ -194,12 +237,6 @@ ...@@ -194,12 +237,6 @@
@implementation TZAlbumCell @implementation TZAlbumCell
/*
- (void)awakeFromNib {
self.posterImageView.clipsToBounds = YES;
}
*/
- (void)setModel:(TZAlbumModel *)model { - (void)setModel:(TZAlbumModel *)model {
_model = model; _model = model;
......
...@@ -42,4 +42,4 @@ typedef enum : NSUInteger { ...@@ -42,4 +42,4 @@ typedef enum : NSUInteger {
@property (nonatomic, strong) NSArray *models; @property (nonatomic, strong) NSArray *models;
@property (nonatomic, strong) NSArray *selectedModels; @property (nonatomic, strong) NSArray *selectedModels;
@property (nonatomic, assign) NSUInteger selectedCount; @property (nonatomic, assign) NSUInteger selectedCount;
@end @end
\ No newline at end of file
...@@ -51,8 +51,12 @@ ...@@ -51,8 +51,12 @@
/// Get photo 获得照片 /// Get photo 获得照片
- (void)getPostImageWithAlbumModel:(TZAlbumModel *)model completion:(void (^)(UIImage *postImage))completion; - (void)getPostImageWithAlbumModel:(TZAlbumModel *)model completion:(void (^)(UIImage *postImage))completion;
- (PHImageRequestID)getPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion; - (PHImageRequestID)getPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
- (PHImageRequestID)getPhotoWithAsset:(id)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion; - (PHImageRequestID)getPhotoWithAsset:(id)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
- (PHImageRequestID)getPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler networkAccessAllowed:(BOOL)networkAccessAllowed;
- (PHImageRequestID)getPhotoWithAsset:(id)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler networkAccessAllowed:(BOOL)networkAccessAllowed;
- (void)getOriginalPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info))completion; - (void)getOriginalPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info))completion;
- (void)getOriginalPhotoDataWithAsset:(id)asset completion:(void (^)(NSData *data,NSDictionary *info))completion; - (void)getOriginalPhotoDataWithAsset:(id)asset completion:(void (^)(NSData *data,NSDictionary *info))completion;
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="grQ-4c-o22" customClass="TZAlbumCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="70"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="MN9-Rx-foD">
<rect key="frame" x="0.0" y="0.0" width="70" height="70"/>
<constraints>
<constraint firstAttribute="width" constant="70" id="9QL-fc-DfO"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Mrv-sA-Nuw">
<rect key="frame" x="80" y="0.0" width="190" height="70"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="TableViewArrow" translatesAutoresizingMaskIntoConstraints="NO" id="Nj8-PM-Kqf">
<rect key="frame" x="293" y="28" width="15" height="15"/>
<constraints>
<constraint firstAttribute="width" constant="15" id="HiN-sC-FNK"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="Mrv-sA-Nuw" firstAttribute="leading" secondItem="MN9-Rx-foD" secondAttribute="trailing" constant="10" id="1QF-Ux-8Eq"/>
<constraint firstAttribute="trailing" secondItem="Mrv-sA-Nuw" secondAttribute="trailing" constant="50" id="Hdc-BO-uDe"/>
<constraint firstAttribute="trailing" secondItem="Nj8-PM-Kqf" secondAttribute="trailing" constant="12" id="NDX-ya-7lu"/>
<constraint firstItem="MN9-Rx-foD" firstAttribute="leading" secondItem="grQ-4c-o22" secondAttribute="leading" id="Qgb-hx-Zng"/>
<constraint firstItem="MN9-Rx-foD" firstAttribute="top" secondItem="grQ-4c-o22" secondAttribute="top" id="ZZm-Sk-o83"/>
<constraint firstAttribute="bottom" secondItem="Mrv-sA-Nuw" secondAttribute="bottom" id="ca9-ki-vgD"/>
<constraint firstAttribute="bottom" secondItem="Nj8-PM-Kqf" secondAttribute="bottom" constant="27" id="cry-id-f46"/>
<constraint firstItem="Mrv-sA-Nuw" firstAttribute="top" secondItem="grQ-4c-o22" secondAttribute="top" id="gZb-1z-CPx"/>
<constraint firstItem="Nj8-PM-Kqf" firstAttribute="top" secondItem="grQ-4c-o22" secondAttribute="top" constant="28" id="rdB-Pt-8ly"/>
<constraint firstAttribute="bottom" secondItem="MN9-Rx-foD" secondAttribute="bottom" id="vxW-5h-txe"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="posterImageView" destination="MN9-Rx-foD" id="tOI-0s-GLe"/>
<outlet property="titleLable" destination="Mrv-sA-Nuw" id="Khi-UM-B6w"/>
</connections>
<point key="canvasLocation" x="584" y="432"/>
</view>
</objects>
<resources>
<image name="TableViewArrow" width="27" height="27"/>
</resources>
</document>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="gTV-IL-0wX" customClass="TZAssetCell">
<rect key="frame" x="0.0" y="0.0" width="80" height="80"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="80" height="80"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Yy8-bS-MRb">
<rect key="frame" x="0.0" y="0.0" width="80" height="80"/>
</imageView>
<button opaque="NO" contentMode="topRight" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dNW-bU-KEf">
<rect key="frame" x="36" y="0.0" width="44" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="35a-xB-9kD"/>
<constraint firstAttribute="width" constant="44" id="c1d-za-0ro"/>
</constraints>
<connections>
<action selector="selectPhotoButtonClick:" destination="gTV-IL-0wX" eventType="touchUpInside" id="XWB-QX-A3P"/>
</connections>
</button>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="photo_def_photoPickerVc@2x" translatesAutoresizingMaskIntoConstraints="NO" id="ova-UI-tV1">
<rect key="frame" x="53" y="0.0" width="27" height="27"/>
<constraints>
<constraint firstAttribute="height" constant="27" id="QwD-vG-feB"/>
<constraint firstAttribute="width" constant="27" id="nLi-1g-3Sr"/>
</constraints>
</imageView>
<view alpha="0.80000000000000004" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="a4Q-ox-UyB" userLabel="VideoView">
<rect key="frame" x="0.0" y="63" width="80" height="17"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="VideoSendIcon" translatesAutoresizingMaskIntoConstraints="NO" id="N0z-qh-hcG">
<rect key="frame" x="8" y="0.0" width="17" height="17"/>
<constraints>
<constraint firstAttribute="width" constant="17" id="1p5-vb-QAu"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="00:12" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="BXd-4T-A1o">
<rect key="frame" x="25" y="0.0" width="49" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="17" id="C2G-yW-u1e"/>
<constraint firstAttribute="trailing" secondItem="BXd-4T-A1o" secondAttribute="trailing" constant="6" id="ET8-ta-Vkb"/>
<constraint firstItem="BXd-4T-A1o" firstAttribute="top" secondItem="a4Q-ox-UyB" secondAttribute="top" id="Uks-Bh-Vdg"/>
<constraint firstAttribute="bottom" secondItem="BXd-4T-A1o" secondAttribute="bottom" id="Uvh-dT-9bi"/>
<constraint firstItem="BXd-4T-A1o" firstAttribute="leading" secondItem="N0z-qh-hcG" secondAttribute="trailing" id="cHE-ea-FX4"/>
<constraint firstItem="N0z-qh-hcG" firstAttribute="top" secondItem="a4Q-ox-UyB" secondAttribute="top" id="dHJ-vE-Lsl"/>
<constraint firstItem="N0z-qh-hcG" firstAttribute="leading" secondItem="a4Q-ox-UyB" secondAttribute="leading" constant="8" id="iq8-Yc-XwI"/>
<constraint firstAttribute="bottom" secondItem="N0z-qh-hcG" secondAttribute="bottom" id="nr0-UX-ihC"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<constraints>
<constraint firstAttribute="trailing" secondItem="a4Q-ox-UyB" secondAttribute="trailing" id="4hT-aw-TYf"/>
<constraint firstAttribute="trailing" secondItem="Yy8-bS-MRb" secondAttribute="trailing" id="5Gq-So-iWs"/>
<constraint firstAttribute="trailing" secondItem="ova-UI-tV1" secondAttribute="trailing" id="GRy-ue-4Qr"/>
<constraint firstItem="ova-UI-tV1" firstAttribute="top" secondItem="gTV-IL-0wX" secondAttribute="top" id="Glw-Yv-tQT"/>
<constraint firstAttribute="bottom" secondItem="Yy8-bS-MRb" secondAttribute="bottom" id="Gsd-C1-gkC"/>
<constraint firstItem="Yy8-bS-MRb" firstAttribute="top" secondItem="gTV-IL-0wX" secondAttribute="top" id="Iv6-lu-ZGo"/>
<constraint firstItem="a4Q-ox-UyB" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" id="OZ3-n0-vkk"/>
<constraint firstAttribute="trailing" secondItem="dNW-bU-KEf" secondAttribute="trailing" id="Ofl-9X-gij"/>
<constraint firstAttribute="bottom" secondItem="a4Q-ox-UyB" secondAttribute="bottom" id="X3A-bD-wef"/>
<constraint firstItem="dNW-bU-KEf" firstAttribute="top" secondItem="gTV-IL-0wX" secondAttribute="top" id="epf-0O-UJg"/>
<constraint firstItem="Yy8-bS-MRb" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" id="s7f-8d-u0B"/>
</constraints>
<connections>
<outlet property="bottomView" destination="a4Q-ox-UyB" id="3k1-bw-ZPW"/>
<outlet property="imageView" destination="Yy8-bS-MRb" id="q1a-cl-0zn"/>
<outlet property="selectImageView" destination="ova-UI-tV1" id="xXa-XQ-rUc"/>
<outlet property="selectPhotoButton" destination="dNW-bU-KEf" id="vDo-uv-cp6"/>
<outlet property="timeLength" destination="BXd-4T-A1o" id="dbx-Cf-g5W"/>
</connections>
</collectionViewCell>
</objects>
<resources>
<image name="VideoSendIcon" width="27" height="27"/>
<image name="photo_def_photoPickerVc@2x" width="27" height="27"/>
</resources>
</document>
...@@ -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.7.2 - 2016.12.5 // version 1.7.3 - 2016.12.6
/* /*
经过测试,比起xib的方式,把TZAssetCell改用纯代码的方式来写,滑动帧数明显提高了(约提高10帧左右) 经过测试,比起xib的方式,把TZAssetCell改用纯代码的方式来写,滑动帧数明显提高了(约提高10帧左右)
...@@ -126,6 +126,9 @@ ...@@ -126,6 +126,9 @@
@property (nonatomic, copy) NSString *settingBtnTitleStr; @property (nonatomic, copy) NSString *settingBtnTitleStr;
@property (nonatomic, copy) NSString *processHintStr; @property (nonatomic, copy) NSString *processHintStr;
/// Public Method
- (void)cancelButtonClick;
// The picker should dismiss itself; when it dismissed these handle will be called. // The picker should dismiss itself; when it dismissed these handle will be called.
// You can also set autoDismiss to NO, then the picker don't dismiss itself. // You can also set autoDismiss to NO, then the picker don't dismiss itself.
// If isOriginalPhoto is YES, user picked the original photo. // If isOriginalPhoto is YES, user picked the original photo.
......
...@@ -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.7.2 - 2016.12.5 // version 1.7.3 - 2016.12.6
#import "TZImagePickerController.h" #import "TZImagePickerController.h"
#import "TZPhotoPickerController.h" #import "TZPhotoPickerController.h"
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
@implementation TZImagePickerController @implementation TZImagePickerController
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor]; self.view.backgroundColor = [UIColor whiteColor];
...@@ -69,10 +71,7 @@ ...@@ -69,10 +71,7 @@
if (iOS9Later) { if (iOS9Later) {
barItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[TZImagePickerController class]]]; barItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[TZImagePickerController class]]];
} else { } else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
barItem = [UIBarButtonItem appearanceWhenContainedIn:[TZImagePickerController class], nil]; barItem = [UIBarButtonItem appearanceWhenContainedIn:[TZImagePickerController class], nil];
#pragma clang diagnostic pop
} }
NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary]; NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
textAttrs[NSForegroundColorAttributeName] = self.barItemTextColor; textAttrs[NSForegroundColorAttributeName] = self.barItemTextColor;
...@@ -83,10 +82,7 @@ ...@@ -83,10 +82,7 @@
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated]; [super viewWillAppear:animated];
_originStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; _originStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[UIApplication sharedApplication].statusBarStyle = iOS7Later ? UIStatusBarStyleLightContent : UIStatusBarStyleBlackOpaque; [UIApplication sharedApplication].statusBarStyle = iOS7Later ? UIStatusBarStyleLightContent : UIStatusBarStyleBlackOpaque;
#pragma clang diagnostic pop
} }
- (void)viewWillDisappear:(BOOL)animated { - (void)viewWillDisappear:(BOOL)animated {
...@@ -177,10 +173,11 @@ ...@@ -177,10 +173,11 @@
previewVc.currentIndex = index; previewVc.currentIndex = index;
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[previewVc setDoneButtonClickBlockWithPreviewType:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { [previewVc setDoneButtonClickBlockWithPreviewType:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
if (weakSelf.didFinishPickingPhotosHandle) { [weakSelf dismissViewControllerAnimated:YES completion:^{
weakSelf.didFinishPickingPhotosHandle(photos,assets,isSelectOriginalPhoto); if (weakSelf.didFinishPickingPhotosHandle) {
} weakSelf.didFinishPickingPhotosHandle(photos,assets,isSelectOriginalPhoto);
[weakSelf dismissViewControllerAnimated:YES completion:nil]; }
}];
}]; }];
} }
return self; return self;
...@@ -236,10 +233,7 @@ ...@@ -236,10 +233,7 @@
[alertController addAction:[UIAlertAction actionWithTitle:[NSBundle tz_localizedStringForKey:@"OK"] style:UIAlertActionStyleDefault handler:nil]]; [alertController addAction:[UIAlertAction actionWithTitle:[NSBundle tz_localizedStringForKey:@"OK"] style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alertController animated:YES completion:nil]; [self presentViewController:alertController animated:YES completion:nil];
} else { } else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[[[UIAlertView alloc] initWithTitle:title message:nil delegate:nil cancelButtonTitle:[NSBundle tz_localizedStringForKey:@"OK"] otherButtonTitles:nil, nil] show]; [[[UIAlertView alloc] initWithTitle:title message:nil delegate:nil cancelButtonTitle:[NSBundle tz_localizedStringForKey:@"OK"] otherButtonTitles:nil, nil] show];
#pragma clang diagnostic pop
} }
} }
...@@ -417,6 +411,31 @@ ...@@ -417,6 +411,31 @@
return UIInterfaceOrientationMaskPortrait; return UIInterfaceOrientationMaskPortrait;
} }
#pragma mark - Public
- (void)cancelButtonClick {
if (self.autoDismiss) {
[self dismissViewControllerAnimated:YES completion:^{
[self callDelegateMethod];
}];
} else {
[self callDelegateMethod];
}
}
- (void)callDelegateMethod {
// 兼容旧版本
if ([self.pickerDelegate respondsToSelector:@selector(imagePickerControllerDidCancel:)]) {
[self.pickerDelegate imagePickerControllerDidCancel:self];
}
if ([self.pickerDelegate respondsToSelector:@selector(tz_imagePickerControllerDidCancel:)]) {
[self.pickerDelegate tz_imagePickerControllerDidCancel:self];
}
if (self.imagePickerControllerDidCancelHandle) {
self.imagePickerControllerDidCancelHandle();
}
}
@end @end
...@@ -433,7 +452,7 @@ ...@@ -433,7 +452,7 @@
self.view.backgroundColor = [UIColor whiteColor]; self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.title = [NSBundle tz_localizedStringForKey:@"Photos"]; self.navigationItem.title = [NSBundle tz_localizedStringForKey:@"Photos"];
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:imagePickerVc.cancelBtnTitleStr style:UIBarButtonItemStylePlain target:self action:@selector(cancel)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:imagePickerVc.cancelBtnTitleStr style:UIBarButtonItemStylePlain target:imagePickerVc action:@selector(cancelButtonClick)];
[self configTableView]; [self configTableView];
// 1.6.10 采用微信的方式,只在相册列表页定义backBarButtonItem为返回,其余的顺系统的做法 // 1.6.10 采用微信的方式,只在相册列表页定义backBarButtonItem为返回,其余的顺系统的做法
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSBundle tz_localizedStringForKey:@"Back"] style:UIBarButtonItemStylePlain target:nil action:nil]; self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSBundle tz_localizedStringForKey:@"Back"] style:UIBarButtonItemStylePlain target:nil action:nil];
...@@ -476,25 +495,6 @@ ...@@ -476,25 +495,6 @@
}]; }];
} }
#pragma mark - Click Event
- (void)cancel {
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
if (imagePickerVc.autoDismiss) {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
// 兼容旧版本
if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerControllerDidCancel:)]) {
[imagePickerVc.pickerDelegate imagePickerControllerDidCancel:imagePickerVc];
}
if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(tz_imagePickerControllerDidCancel:)]) {
[imagePickerVc.pickerDelegate tz_imagePickerControllerDidCancel:imagePickerVc];
}
if (imagePickerVc.imagePickerControllerDidCancelHandle) {
imagePickerVc.imagePickerControllerDidCancelHandle();
}
}
#pragma mark - UITableViewDataSource && Delegate #pragma mark - UITableViewDataSource && Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
...@@ -522,6 +522,7 @@ ...@@ -522,6 +522,7 @@
[self.navigationController pushViewController:photoPickerVc animated:YES]; [self.navigationController pushViewController:photoPickerVc animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:NO]; [tableView deselectRowAtIndexPath:indexPath animated:NO];
} }
#pragma clang diagnostic pop
@end @end
......
...@@ -38,6 +38,8 @@ static CGSize AssetGridThumbnailSize; ...@@ -38,6 +38,8 @@ static CGSize AssetGridThumbnailSize;
@implementation TZPhotoPickerController @implementation TZPhotoPickerController
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (UIImagePickerController *)imagePickerVc { - (UIImagePickerController *)imagePickerVc {
if (_imagePickerVc == nil) { if (_imagePickerVc == nil) {
_imagePickerVc = [[UIImagePickerController alloc] init]; _imagePickerVc = [[UIImagePickerController alloc] init];
...@@ -50,11 +52,8 @@ static CGSize AssetGridThumbnailSize; ...@@ -50,11 +52,8 @@ static CGSize AssetGridThumbnailSize;
tzBarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[TZImagePickerController class]]]; tzBarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[TZImagePickerController class]]];
BarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UIImagePickerController class]]]; BarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UIImagePickerController class]]];
} else { } else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
tzBarItem = [UIBarButtonItem appearanceWhenContainedIn:[TZImagePickerController class], nil]; tzBarItem = [UIBarButtonItem appearanceWhenContainedIn:[TZImagePickerController class], nil];
BarItem = [UIBarButtonItem appearanceWhenContainedIn:[UIImagePickerController class], nil]; BarItem = [UIBarButtonItem appearanceWhenContainedIn:[UIImagePickerController class], nil];
#pragma clang diagnostic pop
} }
NSDictionary *titleTextAttributes = [tzBarItem titleTextAttributesForState:UIControlStateNormal]; NSDictionary *titleTextAttributes = [tzBarItem titleTextAttributesForState:UIControlStateNormal];
[BarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal]; [BarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
...@@ -69,7 +68,7 @@ static CGSize AssetGridThumbnailSize; ...@@ -69,7 +68,7 @@ static CGSize AssetGridThumbnailSize;
_shouldScrollToBottom = YES; _shouldScrollToBottom = YES;
self.view.backgroundColor = [UIColor whiteColor]; self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.title = _model.name; self.navigationItem.title = _model.name;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:tzImagePickerVc.cancelBtnTitleStr style:UIBarButtonItemStylePlain target:self action:@selector(cancel)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:tzImagePickerVc.cancelBtnTitleStr style:UIBarButtonItemStylePlain target:tzImagePickerVc action:@selector(cancelButtonClick)];
_showTakePhotoBtn = (([[TZImageManager manager] isCameraRollAlbum:_model.name]) && tzImagePickerVc.allowTakePicture); _showTakePhotoBtn = (([[TZImageManager manager] isCameraRollAlbum:_model.name]) && tzImagePickerVc.allowTakePicture);
if (!tzImagePickerVc.sortAscendingByModificationDate && _isFirstAppear && iOS8Later) { if (!tzImagePickerVc.sortAscendingByModificationDate && _isFirstAppear && iOS8Later) {
[[TZImageManager manager] getCameraRollAlbum:tzImagePickerVc.allowPickingVideo allowPickingImage:tzImagePickerVc.allowPickingImage completion:^(TZAlbumModel *model) { [[TZImageManager manager] getCameraRollAlbum:tzImagePickerVc.allowPickingVideo allowPickingImage:tzImagePickerVc.allowPickingImage completion:^(TZAlbumModel *model) {
...@@ -243,22 +242,6 @@ static CGSize AssetGridThumbnailSize; ...@@ -243,22 +242,6 @@ static CGSize AssetGridThumbnailSize;
#pragma mark - Click Event #pragma mark - Click Event
- (void)cancel {
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
if (imagePickerVc.autoDismiss) {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(tz_imagePickerControllerDidCancel:)]) {
[imagePickerVc.pickerDelegate tz_imagePickerControllerDidCancel:imagePickerVc];
}
if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerControllerDidCancel:)]) {
[imagePickerVc.pickerDelegate imagePickerControllerDidCancel:imagePickerVc];
}
if (imagePickerVc.imagePickerControllerDidCancelHandle) {
imagePickerVc.imagePickerControllerDidCancelHandle();
}
}
- (void)previewButtonClick { - (void)previewButtonClick {
TZPhotoPreviewController *photoPreviewVc = [[TZPhotoPreviewController alloc] init]; TZPhotoPreviewController *photoPreviewVc = [[TZPhotoPreviewController alloc] init];
[self pushPhotoPrevireViewController:photoPreviewVc]; [self pushPhotoPrevireViewController:photoPreviewVc];
...@@ -286,6 +269,7 @@ static CGSize AssetGridThumbnailSize; ...@@ -286,6 +269,7 @@ static CGSize AssetGridThumbnailSize;
NSMutableArray *infoArr = [NSMutableArray array]; NSMutableArray *infoArr = [NSMutableArray array];
for (NSInteger i = 0; i < tzImagePickerVc.selectedModels.count; i++) { [photos addObject:@1];[assets addObject:@1];[infoArr addObject:@1]; } for (NSInteger i = 0; i < tzImagePickerVc.selectedModels.count; i++) { [photos addObject:@1];[assets addObject:@1];[infoArr addObject:@1]; }
__block BOOL havenotShowAlert = YES;
[TZImageManager manager].shouldFixOrientation = YES; [TZImageManager manager].shouldFixOrientation = YES;
for (NSInteger i = 0; i < tzImagePickerVc.selectedModels.count; i++) { for (NSInteger i = 0; i < tzImagePickerVc.selectedModels.count; i++) {
TZAssetModel *model = tzImagePickerVc.selectedModels[i]; TZAssetModel *model = tzImagePickerVc.selectedModels[i];
...@@ -300,15 +284,38 @@ static CGSize AssetGridThumbnailSize; ...@@ -300,15 +284,38 @@ static CGSize AssetGridThumbnailSize;
for (id item in photos) { if ([item isKindOfClass:[NSNumber class]]) return; } for (id item in photos) { if ([item isKindOfClass:[NSNumber class]]) return; }
[self didGetAllPhotos:photos assets:assets infoArr:infoArr]; if (havenotShowAlert) {
}]; [self didGetAllPhotos:photos assets:assets infoArr:infoArr];
}
} progressHandler:^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
// 如果图片正在从iCloud同步中,提醒用户
if (progress < 1 && havenotShowAlert) {
[tzImagePickerVc hideProgressHUD];
[tzImagePickerVc showAlertWithTitle:[NSBundle tz_localizedStringForKey:@"Synchronizing photos from iCloud"]];
havenotShowAlert = NO;
return;
}
} networkAccessAllowed:YES];
} }
if (tzImagePickerVc.selectedModels.count <= 0) { if (tzImagePickerVc.selectedModels.count <= 0) {
[self didGetAllPhotos:photos assets:assets infoArr:infoArr]; [self didGetAllPhotos:photos assets:assets infoArr:infoArr];
} }
} }
- (void)didGetAllPhotos:(NSArray *)photos assets:(NSArray *)assets infoArr:(NSArray *)infoArr{ - (void)didGetAllPhotos:(NSArray *)photos assets:(NSArray *)assets infoArr:(NSArray *)infoArr {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
[tzImagePickerVc hideProgressHUD];
if (tzImagePickerVc.autoDismiss) {
[self.navigationController dismissViewControllerAnimated:YES completion:^{
[self callDelegateMethodWithPhotos:photos assets:assets infoArr:infoArr];
}];
} else {
[self callDelegateMethodWithPhotos:photos assets:assets infoArr:infoArr];
}
}
- (void)callDelegateMethodWithPhotos:(NSArray *)photos assets:(NSArray *)assets infoArr:(NSArray *)infoArr {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if ([tzImagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerController:didFinishPickingPhotos:sourceAssets:isSelectOriginalPhoto:)]) { if ([tzImagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerController:didFinishPickingPhotos:sourceAssets:isSelectOriginalPhoto:)]) {
[tzImagePickerVc.pickerDelegate imagePickerController:tzImagePickerVc didFinishPickingPhotos:photos sourceAssets:assets isSelectOriginalPhoto:_isSelectOriginalPhoto]; [tzImagePickerVc.pickerDelegate imagePickerController:tzImagePickerVc didFinishPickingPhotos:photos sourceAssets:assets isSelectOriginalPhoto:_isSelectOriginalPhoto];
...@@ -322,11 +329,6 @@ static CGSize AssetGridThumbnailSize; ...@@ -322,11 +329,6 @@ static CGSize AssetGridThumbnailSize;
if (tzImagePickerVc.didFinishPickingPhotosWithInfosHandle) { if (tzImagePickerVc.didFinishPickingPhotosWithInfosHandle) {
tzImagePickerVc.didFinishPickingPhotosWithInfosHandle(photos,assets,_isSelectOriginalPhoto,infoArr); tzImagePickerVc.didFinishPickingPhotosWithInfosHandle(photos,assets,_isSelectOriginalPhoto,infoArr);
} }
[tzImagePickerVc hideProgressHUD];
if (tzImagePickerVc.autoDismiss) {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
} }
#pragma mark - UICollectionViewDataSource && Delegate #pragma mark - UICollectionViewDataSource && Delegate
...@@ -438,15 +440,12 @@ static CGSize AssetGridThumbnailSize; ...@@ -438,15 +440,12 @@ static CGSize AssetGridThumbnailSize;
- (void)takePhoto { - (void)takePhoto {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if ((authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied) && iOS7Later) { if ((authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied) && iOS7Later) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// 无权限 做一个友好的提示 // 无权限 做一个友好的提示
NSString *appName = [[NSBundle mainBundle].infoDictionary valueForKey:@"CFBundleDisplayName"]; NSString *appName = [[NSBundle mainBundle].infoDictionary valueForKey:@"CFBundleDisplayName"];
if (!appName) appName = [[NSBundle mainBundle].infoDictionary valueForKey:@"CFBundleName"]; if (!appName) appName = [[NSBundle mainBundle].infoDictionary valueForKey:@"CFBundleName"];
NSString *message = [NSString stringWithFormat:[NSBundle tz_localizedStringForKey:@"Please allow %@ to access your camera in \"Settings -> Privacy -> Camera\""],appName]; NSString *message = [NSString stringWithFormat:[NSBundle tz_localizedStringForKey:@"Please allow %@ to access your camera in \"Settings -> Privacy -> Camera\""],appName];
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:[NSBundle tz_localizedStringForKey:@"Can not use camera"] message:message delegate:self cancelButtonTitle:[NSBundle tz_localizedStringForKey:@"Cancel"] otherButtonTitles:[NSBundle tz_localizedStringForKey:@"Setting"], nil]; UIAlertView * alert = [[UIAlertView alloc]initWithTitle:[NSBundle tz_localizedStringForKey:@"Can not use camera"] message:message delegate:self cancelButtonTitle:[NSBundle tz_localizedStringForKey:@"Cancel"] otherButtonTitles:[NSBundle tz_localizedStringForKey:@"Setting"], nil];
[alert show]; [alert show];
#pragma clang diagnostic pop
} else { // 调用相机 } else { // 调用相机
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
...@@ -547,10 +546,7 @@ static CGSize AssetGridThumbnailSize; ...@@ -547,10 +546,7 @@ static CGSize AssetGridThumbnailSize;
#pragma mark - UIAlertViewDelegate #pragma mark - UIAlertViewDelegate
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
#pragma clang diagnostic pop
if (buttonIndex == 1) { // 去设置界面,开启相机访问权限 if (buttonIndex == 1) { // 去设置界面,开启相机访问权限
if (iOS8Later) { if (iOS8Later) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
...@@ -581,11 +577,13 @@ static CGSize AssetGridThumbnailSize; ...@@ -581,11 +577,13 @@ static CGSize AssetGridThumbnailSize;
} else { } else {
image = [info objectForKey:UIImagePickerControllerOriginalImage]; image = [info objectForKey:UIImagePickerControllerOriginalImage];
} }
[[TZImageManager manager] savePhotoWithImage:image completion:^(NSError *error){ if (image) {
if (!error) { [[TZImageManager manager] savePhotoWithImage:image completion:^(NSError *error){
[self reloadPhotoArray]; if (!error) {
} [self reloadPhotoArray];
}]; }
}];
}
} }
} }
...@@ -627,6 +625,10 @@ static CGSize AssetGridThumbnailSize; ...@@ -627,6 +625,10 @@ static CGSize AssetGridThumbnailSize;
[picker dismissViewControllerAnimated:YES completion:nil]; [picker dismissViewControllerAnimated:YES completion:nil];
} }
- (void)dealloc {
//NSLog(@"TZPhotoPickerController dealloc");
}
#pragma mark - Asset Caching #pragma mark - Asset Caching
- (void)resetCachedAssets { - (void)resetCachedAssets {
...@@ -735,6 +737,7 @@ static CGSize AssetGridThumbnailSize; ...@@ -735,6 +737,7 @@ static CGSize AssetGridThumbnailSize;
} }
return indexPaths; return indexPaths;
} }
#pragma clang diagnostic pop
@end @end
......
...@@ -8,15 +8,17 @@ ...@@ -8,15 +8,17 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@class TZAssetModel; @class TZAssetModel,TZProgressView;
@interface TZPhotoPreviewCell : UICollectionViewCell @interface TZPhotoPreviewCell : UICollectionViewCell
@property (nonatomic, strong) TZAssetModel *model; @property (nonatomic, strong) TZAssetModel *model;
@property (nonatomic, copy) void (^singleTapGestureBlock)(); @property (nonatomic, copy) void (^singleTapGestureBlock)();
@property (nonatomic, copy) void (^imageProgressUpdateBlock)(double progress);
@property (nonatomic, strong) UIImageView *imageView; @property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIScrollView *scrollView; @property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *imageContainerView; @property (nonatomic, strong) UIView *imageContainerView;
@property (nonatomic, strong) TZProgressView *progressView;
@property (nonatomic, assign) BOOL allowCrop; @property (nonatomic, assign) BOOL allowCrop;
@property (nonatomic, assign) CGRect cropRect; @property (nonatomic, assign) CGRect cropRect;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "TZAssetModel.h" #import "TZAssetModel.h"
#import "UIView+Layout.h" #import "UIView+Layout.h"
#import "TZImageManager.h" #import "TZImageManager.h"
#import "TZProgressView.h"
@interface TZPhotoPreviewCell ()<UIGestureRecognizerDelegate,UIScrollViewDelegate> { @interface TZPhotoPreviewCell ()<UIGestureRecognizerDelegate,UIScrollViewDelegate> {
CGFloat _aspectRatio; CGFloat _aspectRatio;
...@@ -55,17 +56,42 @@ ...@@ -55,17 +56,42 @@
tap2.numberOfTapsRequired = 2; tap2.numberOfTapsRequired = 2;
[tap1 requireGestureRecognizerToFail:tap2]; [tap1 requireGestureRecognizerToFail:tap2];
[self addGestureRecognizer:tap2]; [self addGestureRecognizer:tap2];
[self configProgressView];
} }
return self; return self;
} }
- (void)configProgressView {
_progressView = [[TZProgressView alloc] init];
static CGFloat progressWH = 40;
CGFloat progressX = (self.tz_width - progressWH) / 2;
CGFloat progressY = (self.tz_height - progressWH) / 2;
_progressView.frame = CGRectMake(progressX, progressY, progressWH, progressWH);
_progressView.hidden = YES;
[self addSubview:_progressView];
}
- (void)setModel:(TZAssetModel *)model { - (void)setModel:(TZAssetModel *)model {
_model = model; _model = model;
[_scrollView setZoomScale:1.0 animated:NO]; [_scrollView setZoomScale:1.0 animated:NO];
[[TZImageManager manager] getPhotoWithAsset:model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) { [[TZImageManager manager] getPhotoWithAsset:model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
self.imageView.image = photo; self.imageView.image = photo;
[self resizeSubviews]; [self resizeSubviews];
}]; _progressView.hidden = YES;
if (self.imageProgressUpdateBlock) {
self.imageProgressUpdateBlock(1);
}
} progressHandler:^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
_progressView.hidden = NO;
[self bringSubviewToFront:_progressView];
progress = progress > 0.02 ? progress : 0.02;;
_progressView.progress = progress;
if (self.imageProgressUpdateBlock) {
self.imageProgressUpdateBlock(progress);
}
} networkAccessAllowed:YES];
} }
- (void)recoverSubviews { - (void)recoverSubviews {
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
@property (nonatomic, assign) BOOL isHideNaviBar; @property (nonatomic, assign) BOOL isHideNaviBar;
@property (nonatomic, strong) UIView *cropBgView; @property (nonatomic, strong) UIView *cropBgView;
@property (nonatomic, strong) UIView *cropView; @property (nonatomic, strong) UIView *cropView;
@property (nonatomic, assign) double progress;
@end @end
@implementation TZPhotoPreviewController @implementation TZPhotoPreviewController
...@@ -80,13 +82,12 @@ ...@@ -80,13 +82,12 @@
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
_naviBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.tz_width, 64)]; _naviBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.tz_width, 64)];
_naviBar.backgroundColor = [UIColor colorWithRed:(34/255.0) green:(34/255.0) blue:(34/255.0) alpha:1.0]; _naviBar.backgroundColor = [UIColor colorWithRed:(34/255.0) green:(34/255.0) blue:(34/255.0) alpha:0.7];
_naviBar.alpha = 0.7;
_backButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 44, 44)]; _backButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 44, 44)];
[_backButton setImage:[UIImage imageNamedFromMyBundle:@"navi_back.png"] forState:UIControlStateNormal]; [_backButton setImage:[UIImage imageNamedFromMyBundle:@"navi_back.png"] forState:UIControlStateNormal];
[_backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; [_backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
_selectButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.tz_width - 54, 10, 42, 42)]; _selectButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.tz_width - 54, 10, 42, 42)];
[_selectButton setImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoDefImageName] forState:UIControlStateNormal]; [_selectButton setImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoDefImageName] forState:UIControlStateNormal];
...@@ -102,8 +103,7 @@ ...@@ -102,8 +103,7 @@
- (void)configBottomToolBar { - (void)configBottomToolBar {
_toolBar = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.tz_height - 44, self.view.tz_width, 44)]; _toolBar = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.tz_height - 44, self.view.tz_width, 44)];
static CGFloat rgb = 34 / 255.0; static CGFloat rgb = 34 / 255.0;
_toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:1.0]; _toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.7];
_toolBar.alpha = 0.7;
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (_tzImagePickerVc.allowPickingOriginalPhoto) { if (_tzImagePickerVc.allowPickingOriginalPhoto) {
...@@ -267,7 +267,7 @@ ...@@ -267,7 +267,7 @@
[UIView showOscillatoryAnimationWithLayer:_numberImageView.layer type:TZOscillatoryAnimationToSmaller]; [UIView showOscillatoryAnimationWithLayer:_numberImageView.layer type:TZOscillatoryAnimationToSmaller];
} }
- (void)back { - (void)backButtonClick {
if (self.navigationController.childViewControllers.count < 2) { if (self.navigationController.childViewControllers.count < 2) {
[self.navigationController dismissViewControllerAnimated:YES completion:nil]; [self.navigationController dismissViewControllerAnimated:YES completion:nil];
return; return;
...@@ -280,6 +280,11 @@ ...@@ -280,6 +280,11 @@
- (void)doneButtonClick { - (void)doneButtonClick {
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
// 如果图片正在从iCloud同步中,提醒用户
if (_progress > 0 && _progress < 1) {
[_tzImagePickerVc showAlertWithTitle:[NSBundle tz_localizedStringForKey:@"Synchronizing photos from iCloud"]]; return;
}
// 如果没有选中过照片 点击确定时选中当前预览的照片 // 如果没有选中过照片 点击确定时选中当前预览的照片
if (_tzImagePickerVc.selectedModels.count == 0 && _tzImagePickerVc.minImagesCount <= 0) { if (_tzImagePickerVc.selectedModels.count == 0 && _tzImagePickerVc.minImagesCount <= 0) {
TZAssetModel *model = _models[_currentIndex]; TZAssetModel *model = _models[_currentIndex];
...@@ -354,6 +359,9 @@ ...@@ -354,6 +359,9 @@
weakToolBar.hidden = weakSelf.isHideNaviBar; weakToolBar.hidden = weakSelf.isHideNaviBar;
}; };
} }
[cell setImageProgressUpdateBlock:^(double progress) {
weakSelf.progress = progress;
}];
return cell; return cell;
} }
...@@ -372,7 +380,7 @@ ...@@ -372,7 +380,7 @@
#pragma mark - Private Method #pragma mark - Private Method
- (void)dealloc { - (void)dealloc {
// NSLog(@"dealloc"); //NSLog(@"TZPhotoPreviewController dealloc");
} }
- (void)refreshNaviBarAndBottomBarState { - (void)refreshNaviBarAndBottomBarState {
......
//
// TZProgressView.h
// TZImagePickerController
//
// Created by ttouch on 2016/12/6.
// Copyright © 2016年 谭真. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TZProgressView : UIView
@property (nonatomic, assign) double progress;
@end
//
// TZProgressView.m
// TZImagePickerController
//
// Created by ttouch on 2016/12/6.
// Copyright © 2016年 谭真. All rights reserved.
//
#import "TZProgressView.h"
@interface TZProgressView ()
@property (nonatomic, strong) CAShapeLayer *progressLayer;
@end
@implementation TZProgressView
- (instancetype)init {
self = [super init];
if (self) {
self.backgroundColor = [UIColor clearColor];
_progressLayer = [CAShapeLayer layer];
_progressLayer.fillColor = [[UIColor clearColor] CGColor];
_progressLayer.strokeColor = [[UIColor whiteColor] CGColor];
_progressLayer.opacity = 1;
_progressLayer.lineCap = kCALineCapRound;
_progressLayer.lineWidth = 5;
[_progressLayer setShadowColor:[UIColor blackColor].CGColor];
[_progressLayer setShadowOffset:CGSizeMake(1, 1)];
[_progressLayer setShadowOpacity:0.5];
[_progressLayer setShadowRadius:2];
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGPoint center = CGPointMake(rect.size.width / 2, rect.size.height / 2);
CGFloat radius = rect.size.width / 2;
CGFloat startA = - M_PI_2;
CGFloat endA = - M_PI_2 + M_PI * 2 * _progress;
_progressLayer.frame = self.bounds;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
_progressLayer.path =[path CGPath];
[_progressLayer removeFromSuperlayer];
[self.layer addSublayer:_progressLayer];
}
- (void)setProgress:(double)progress {
_progress = progress;
[self setNeedsDisplay];
}
@end
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
UIImage *_cover; UIImage *_cover;
UIView *_toolBar; UIView *_toolBar;
UIButton *_okButton; UIButton *_doneButton;
UIProgressView *_progress; UIProgressView *_progress;
} }
@end @end
...@@ -81,16 +81,16 @@ ...@@ -81,16 +81,16 @@
_toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:1.0]; _toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:1.0];
_toolBar.alpha = 0.7; _toolBar.alpha = 0.7;
_okButton = [UIButton buttonWithType:UIButtonTypeCustom]; _doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
_okButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44); _doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
_okButton.titleLabel.font = [UIFont systemFontOfSize:16]; _doneButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_okButton addTarget:self action:@selector(okButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
[_okButton setTitle:tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal]; [_doneButton setTitle:tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal];
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
[_okButton setTitleColor:imagePickerVc.oKButtonTitleColorNormal forState:UIControlStateNormal]; [_doneButton setTitleColor:imagePickerVc.oKButtonTitleColorNormal forState:UIControlStateNormal];
[_toolBar addSubview:_okButton]; [_toolBar addSubview:_doneButton];
[self.view addSubview:_toolBar]; [self.view addSubview:_toolBar];
} }
...@@ -111,7 +111,22 @@ ...@@ -111,7 +111,22 @@
} }
} }
- (void)okButtonClick { - (void)doneButtonClick {
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
if (self.navigationController) {
if (imagePickerVc.autoDismiss) {
[self.navigationController dismissViewControllerAnimated:YES completion:^{
[self callDelegateMethod];
}];
}
} else {
[self dismissViewControllerAnimated:YES completion:^{
[self callDelegateMethod];
}];
}
}
- (void)callDelegateMethod {
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerController:didFinishPickingVideo:sourceAssets:)]) { if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerController:didFinishPickingVideo:sourceAssets:)]) {
[imagePickerVc.pickerDelegate imagePickerController:imagePickerVc didFinishPickingVideo:_cover sourceAssets:_model.asset]; [imagePickerVc.pickerDelegate imagePickerController:imagePickerVc didFinishPickingVideo:_cover sourceAssets:_model.asset];
...@@ -119,13 +134,6 @@ ...@@ -119,13 +134,6 @@
if (imagePickerVc.didFinishPickingVideoHandle) { if (imagePickerVc.didFinishPickingVideoHandle) {
imagePickerVc.didFinishPickingVideoHandle(_cover,_model.asset); imagePickerVc.didFinishPickingVideoHandle(_cover,_model.asset);
} }
if (self.navigationController) {
if (imagePickerVc.autoDismiss) {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
} else {
[self dismissViewControllerAnimated:YES completion:nil];
}
} }
#pragma mark - Notification Method #pragma mark - Notification Method
......
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
@implementation ViewController @implementation ViewController
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (UIImagePickerController *)imagePickerVc { - (UIImagePickerController *)imagePickerVc {
if (_imagePickerVc == nil) { if (_imagePickerVc == nil) {
_imagePickerVc = [[UIImagePickerController alloc] init]; _imagePickerVc = [[UIImagePickerController alloc] init];
...@@ -51,11 +53,8 @@ ...@@ -51,11 +53,8 @@
tzBarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[TZImagePickerController class]]]; tzBarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[TZImagePickerController class]]];
BarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UIImagePickerController class]]]; BarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UIImagePickerController class]]];
} else { } else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
tzBarItem = [UIBarButtonItem appearanceWhenContainedIn:[TZImagePickerController class], nil]; tzBarItem = [UIBarButtonItem appearanceWhenContainedIn:[TZImagePickerController class], nil];
BarItem = [UIBarButtonItem appearanceWhenContainedIn:[UIImagePickerController class], nil]; BarItem = [UIBarButtonItem appearanceWhenContainedIn:[UIImagePickerController class], nil];
#pragma clang diagnostic pop
} }
NSDictionary *titleTextAttributes = [tzBarItem titleTextAttributesForState:UIControlStateNormal]; NSDictionary *titleTextAttributes = [tzBarItem titleTextAttributesForState:UIControlStateNormal];
[BarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal]; [BarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
...@@ -121,10 +120,7 @@ ...@@ -121,10 +120,7 @@
if (indexPath.row == _selectedPhotos.count) { if (indexPath.row == _selectedPhotos.count) {
BOOL showSheet = self.showSheetSwitch.isOn; BOOL showSheet = self.showSheetSwitch.isOn;
if (showSheet) { if (showSheet) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"去相册选择", nil]; UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"去相册选择", nil];
#pragma clang diagnostic pop
[sheet showInView:self.view]; [sheet showInView:self.view];
} else { } else {
[self pushImagePickerController]; [self pushImagePickerController];
...@@ -135,12 +131,9 @@ ...@@ -135,12 +131,9 @@
if ([asset isKindOfClass:[PHAsset class]]) { if ([asset isKindOfClass:[PHAsset class]]) {
PHAsset *phAsset = asset; PHAsset *phAsset = asset;
isVideo = phAsset.mediaType == PHAssetMediaTypeVideo; isVideo = phAsset.mediaType == PHAssetMediaTypeVideo;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
} else if ([asset isKindOfClass:[ALAsset class]]) { } else if ([asset isKindOfClass:[ALAsset class]]) {
ALAsset *alAsset = asset; ALAsset *alAsset = asset;
isVideo = [[alAsset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]; isVideo = [[alAsset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo];
#pragma clang diagnostic pop
} }
if (isVideo) { // perview video / 预览视频 if (isVideo) { // perview video / 预览视频
TZVideoPlayerController *vc = [[TZVideoPlayerController alloc] init]; TZVideoPlayerController *vc = [[TZVideoPlayerController alloc] init];
...@@ -257,11 +250,8 @@ ...@@ -257,11 +250,8 @@
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if ((authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) && iOS7Later) { if ((authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) && iOS7Later) {
// 无相机权限 做一个友好的提示 // 无相机权限 做一个友好的提示
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法使用相机" message:@"请在iPhone的""设置-隐私-相机""中允许访问相机" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil]; UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法使用相机" message:@"请在iPhone的""设置-隐私-相机""中允许访问相机" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil];
[alert show]; [alert show];
#define push @#clang diagnostic pop
// 拍照之前还需要检查相册权限 // 拍照之前还需要检查相册权限
} else if ([[TZImageManager manager] authorizationStatus] == 2) { // 已被拒绝,没有相册权限,将无法保存拍的照片 } else if ([[TZImageManager manager] authorizationStatus] == 2) { // 已被拒绝,没有相册权限,将无法保存拍的照片
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法访问相册" message:@"请在iPhone的""设置-隐私-相册""中允许访问相册" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil]; UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法访问相册" message:@"请在iPhone的""设置-隐私-相册""中允许访问相册" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil];
...@@ -324,10 +314,7 @@ ...@@ -324,10 +314,7 @@
#pragma mark - UIActionSheetDelegate #pragma mark - UIActionSheetDelegate
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
#pragma clang diagnostic pop
if (buttonIndex == 0) { // take photo / 去拍照 if (buttonIndex == 0) { // take photo / 去拍照
[self takePhoto]; [self takePhoto];
} else if (buttonIndex == 1) { } else if (buttonIndex == 1) {
...@@ -337,10 +324,7 @@ ...@@ -337,10 +324,7 @@
#pragma mark - UIAlertViewDelegate #pragma mark - UIAlertViewDelegate
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
#pragma clang diagnostic pop
if (buttonIndex == 1) { // 去设置界面,开启相机访问权限 if (buttonIndex == 1) { // 去设置界面,开启相机访问权限
if (iOS8Later) { if (iOS8Later) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
...@@ -471,12 +455,13 @@ ...@@ -471,12 +455,13 @@
ALAsset *alAsset = (ALAsset *)asset; ALAsset *alAsset = (ALAsset *)asset;
fileName = alAsset.defaultRepresentation.filename;; fileName = alAsset.defaultRepresentation.filename;;
} }
NSLog(@"图片名字:%@",fileName); //NSLog(@"图片名字:%@",fileName);
} }
} }
- (UIInterfaceOrientationMask)supportedInterfaceOrientations { - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait; return UIInterfaceOrientationMaskPortrait;
} }
#pragma clang diagnostic pop
@end @end
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