Skip to content

Commit

Permalink
1.7.7 支持GIF图片
Browse files Browse the repository at this point in the history
  • Loading branch information
banchichen committed Dec 13, 2016
1 parent e8c2535 commit 34c192f
Show file tree
Hide file tree
Showing 18 changed files with 150 additions and 98 deletions.
4 changes: 2 additions & 2 deletions TZImagePickerController.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = "TZImagePickerController"
s.version = "1.7.6"
s.version = "1.7.7"
s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video"
s.homepage = "https://github.com/banchichen/TZImagePickerController"
s.license = "MIT"
s.author = { "banchichen" => "tanzhenios@foxmail.com" }
s.platform = :ios
s.ios.deployment_target = "6.0"
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.7.6" }
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.7.7" }
s.requires_arc = true
s.resources = "TZImagePickerController/TZImagePickerController/*.{png,xib,nib,bundle}"
s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}"
Expand Down
1 change: 1 addition & 0 deletions TZImagePickerController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@
900E657B1C2BB8D5003D9A9E = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = ZH74J4ERQH;
ProvisioningStyle = Automatic;
};
900E65941C2BB8D5003D9A9E = {
CreatedOnToolsVersion = 7.2;
Expand Down
47 changes: 35 additions & 12 deletions TZImagePickerController/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4Ae-5T-gEc" userLabel="TopContentView">
<rect key="frame" x="0.0" y="0.0" width="320" height="370"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="405"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="obE-hs-XLa" userLabel="View1">
Expand Down Expand Up @@ -107,7 +107,7 @@
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jKt-h1-BC7" userLabel="View5">
<rect key="frame" x="0.0" y="160" width="320" height="35"/>
<rect key="frame" x="0.0" y="195" width="320" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4L3-Da-pcd">
Expand All @@ -127,8 +127,8 @@
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Qrr-87-KzM" userLabel="View6">
<rect key="frame" x="0.0" y="195" width="320" height="35"/>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Qrr-87-KzM" userLabel="View7">
<rect key="frame" x="0.0" y="230" width="320" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="uHt-bT-lBZ">
Expand All @@ -148,8 +148,8 @@
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="PA2-zk-4Ey" userLabel="View7">
<rect key="frame" x="0.0" y="230" width="320" height="35"/>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="PA2-zk-4Ey" userLabel="View8">
<rect key="frame" x="0.0" y="265" width="320" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<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="rK3-1U-kcW">
Expand All @@ -168,8 +168,8 @@
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VUP-wm-Ah2" userLabel="View8">
<rect key="frame" x="0.0" y="265" width="320" height="35"/>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VUP-wm-Ah2" userLabel="View9">
<rect key="frame" x="0.0" y="300" width="320" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<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="fbH-6q-oeE">
Expand All @@ -188,8 +188,8 @@
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="92q-n9-Zwf" userLabel="View9">
<rect key="frame" x="0.0" y="300" width="320" height="35"/>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="92q-n9-Zwf" userLabel="View10">
<rect key="frame" x="0.0" y="335" width="320" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="0ju-HJ-A06">
Expand All @@ -209,8 +209,8 @@
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uex-bO-uvg" userLabel="View10">
<rect key="frame" x="0.0" y="335" width="320" height="35"/>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uex-bO-uvg" userLabel="View11">
<rect key="frame" x="0.0" y="370" width="320" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="hsH-wt-l1R">
Expand All @@ -230,13 +230,36 @@
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gde-hr-2Sy" userLabel="View6">
<rect key="frame" x="0.0" y="160" width="320" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="zLj-vc-Xwz">
<rect key="frame" x="225" y="2" width="51" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="allowPickingGifSwitchClick:" destination="BYZ-38-t0r" eventType="valueChanged" id="O9W-7a-uc8"/>
<action selector="allowPickingOriginPhotoSwitchClick:" destination="BYZ-38-t0r" eventType="valueChanged" id="Y1n-2W-q5O"/>
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="允许选择Gif图片" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ly2-uJ-7DN">
<rect key="frame" x="0.0" y="0.0" width="200" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</subviews>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<connections>
<outlet property="allowCropSwitch" destination="0ju-HJ-A06" id="PHl-Yf-uf2"/>
<outlet property="allowPickingGifSwitch" destination="zLj-vc-Xwz" id="1UG-vY-alU"/>
<outlet property="allowPickingImageSwitch" destination="iRQ-aE-1KG" id="V7a-u6-cLv"/>
<outlet property="allowPickingOriginalPhotoSwitch" destination="4L3-Da-pcd" id="KFm-Zl-dpD"/>
<outlet property="allowPickingVideoSwitch" destination="a58-aK-ZB0" id="9Ti-hW-QRj"/>
Expand Down
2 changes: 1 addition & 1 deletion TZImagePickerController/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.7.6</string>
<string>1.7.7</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
#import "TZAssetModel.h"
#import "UIView+Layout.h"
#import "TZPhotoPreviewCell.h"
#import "TZImageManager.h"

@interface TZGifPhotoPreviewController () {
UIView *_toolBar;
UIButton *_doneButton;
UIProgressView *_progress;

TZPhotoPreviewView *_previewView;

UIStatusBarStyle _originStatusBarStyle;
}
@end

Expand All @@ -27,11 +30,24 @@ - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
self.navigationItem.title = [NSString stringWithFormat:@"GIF%@",tzImagePickerVc.previewBtnTitleStr];
if (tzImagePickerVc) {
self.navigationItem.title = [NSString stringWithFormat:@"GIF %@",tzImagePickerVc.previewBtnTitleStr];
}
[self configPreviewView];
[self configBottomToolBar];
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_originStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
[UIApplication sharedApplication].statusBarStyle = iOS7Later ? UIStatusBarStyleLightContent : UIStatusBarStyleBlackOpaque;
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[UIApplication sharedApplication].statusBarStyle = _originStatusBarStyle;
}

- (void)configPreviewView {
_previewView = [[TZPhotoPreviewView alloc] initWithFrame:self.view.bounds];
_previewView.scrollView.frame = self.view.bounds;
Expand All @@ -46,19 +62,31 @@ - (void)configPreviewView {
- (void)configBottomToolBar {
_toolBar = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.tz_height - 44, self.view.tz_width, 44)];
CGFloat rgb = 34 / 255.0;
_toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:1.0];
_toolBar.alpha = 0.7;
_toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.7];

_doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
_doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
_doneButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
[_doneButton setTitle:tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal];
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
[_doneButton setTitleColor:imagePickerVc.oKButtonTitleColorNormal forState:UIControlStateNormal];

if (tzImagePickerVc) {
[_doneButton setTitle:tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal];
[_doneButton setTitleColor:tzImagePickerVc.oKButtonTitleColorNormal forState:UIControlStateNormal];
} else {
[_doneButton setTitle:[NSBundle tz_localizedStringForKey:@"Done"] forState:UIControlStateNormal];
[_doneButton setTitleColor:[UIColor colorWithRed:(83/255.0) green:(179/255.0) blue:(17/255.0) alpha:1.0] forState:UIControlStateNormal];
}
[_toolBar addSubview:_doneButton];

UILabel *byteLable = [[UILabel alloc] init];
byteLable.textColor = [UIColor whiteColor];
byteLable.font = [UIFont systemFontOfSize:13];
byteLable.frame = CGRectMake(10, 0, 100, 44);
[[TZImageManager manager] getPhotosBytesWithArray:@[_model] completion:^(NSString *totalBytes) {
byteLable.text = totalBytes;
}];
[_toolBar addSubview:byteLable];

[self.view addSubview:_toolBar];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
@end


/// 该分类的代码来自SDWebImage:https://github.com/rs/SDWebImage
/// 为了防止冲突,我将分类名字和方法名字做了修改
@interface UIImage (TZGif)

- (UIImage *)sd_tz_animatedImageByScalingAndCroppingToSize:(CGSize)size;

+ (UIImage *)sd_tz_animatedGIFWithData:(NSData *)data;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -114,43 +114,6 @@ + (UIImage *)circularClipImage:(UIImage *)image {

@implementation UIImage (TZGif)

- (UIImage *)sd_tz_animatedImageByScalingAndCroppingToSize:(CGSize)size {
if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) {
return self;
}

CGSize scaledSize = size;
CGPoint thumbnailPoint = CGPointZero;

CGFloat widthFactor = size.width / self.size.width;
CGFloat heightFactor = size.height / self.size.height;
CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor;
scaledSize.width = self.size.width * scaleFactor;
scaledSize.height = self.size.height * scaleFactor;

if (widthFactor > heightFactor) {
thumbnailPoint.y = (size.height - scaledSize.height) * 0.5;
}
else if (widthFactor < heightFactor) {
thumbnailPoint.x = (size.width - scaledSize.width) * 0.5;
}

NSMutableArray *scaledImages = [NSMutableArray array];

for (UIImage *image in self.images) {
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);

[image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

[scaledImages addObject:newImage];

UIGraphicsEndImageContext();
}

return [UIImage animatedImageWithImages:scaledImages duration:self.duration];
}

+ (UIImage *)sd_tz_animatedGIFWithData:(NSData *)data {
if (!data) {
return nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ - (void)getOriginalPhotoDataWithAsset:(id)asset completion:(void (^)(NSData *dat

- (void)savePhotoWithImage:(UIImage *)image completion:(void (^)(NSError *error))completion {
NSData *data = UIImageJPEGRepresentation(image, 0.9);
if (iOS9Later) { // 这里有坑... iOS8系统下这个方法保存图片会失败
if (iOS9Later) { // 这里有坑... iOS8系统下这个方法保存图片会失败 原来是因为PHAssetResourceType是iOS9之后的...
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
options.shouldMoveFile = YES;
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 34c192f

Please sign in to comment.