├── .gitignore ├── JQImagePicker.podspec ├── JQImagePicker ├── JQImageCropperViewController.h ├── JQImageCropperViewController.m ├── JQImagePicker.h └── JQImagePicker.m ├── JQImagePickerDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── JQImagePickerDemo ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── UIImage+GCAdd.h ├── UIImage+GCAdd.m ├── ViewController.h ├── ViewController.m └── main.m ├── JQImagePickerDemoTests ├── Info.plist └── JQImagePickerDemoTests.m ├── JQImagePickerDemoUITests ├── Info.plist └── JQImagePickerDemoUITests.m ├── LICENSE ├── README.md ├── 效果图1.gif └── 效果图2.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | # Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | -------------------------------------------------------------------------------- /JQImagePicker.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "JQImagePicker" 3 | s.version = "1.0.1" 4 | s.summary = "IOS photos custom cut, custom width ratio cut, code calls simple refining." 5 | s.homepage = "https://github.com/xiaohange/JQImagePicker" 6 | s.license = { :type => "MIT", :file => "LICENSE" } 7 | s.author = { "韩俊强" => "532167805@qq.com" } 8 | s.platform = :ios, "8.0" 9 | s.ios.deployment_target = "8.0" 10 | s.source = { :git => "https://github.com/xiaohange/JQImagePicker.git", :tag => s.version.to_s } 11 | s.source_files = "JQImagePicker/**/*.{h,m}" 12 | s.public_header_files = "JQImagePicker/**/*.h" 13 | s.requires_arc = true 14 | end 15 | -------------------------------------------------------------------------------- /JQImagePicker/JQImageCropperViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JQImageCropperViewController.h 3 | // 4 | // Created by 韩俊强 on 12/30/13. 5 | // Copyright (c) 2013 HaRi. All rights reserved. 6 | // 手机加iOS开发者交流群:①群:446310206 ②群:426087546 7 | // 8 | 9 | #import 10 | 11 | typedef void(^submitBlock)(UIViewController *viewController , UIImage *image); 12 | typedef void(^cancelBlock)(UIViewController *viewController); 13 | 14 | @interface JQImageCropperViewController : UIViewController 15 | @property (nonatomic, copy) submitBlock submitblock; 16 | @property (nonatomic, copy) cancelBlock cancelblock; 17 | @property (nonatomic, assign) CGRect cropFrame; 18 | 19 | - (id)initWithImage:(UIImage *)originalImage cropFrame:(CGRect)cropFrame limitScaleRatio:(NSInteger)limitRatio; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /JQImagePicker/JQImageCropperViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JQImageCropperViewController.m 3 | // 4 | // Created by 韩俊强 on 12/30/13. 5 | // Copyright (c) 2013 HaRi. All rights reserved. 6 | // 手机加iOS开发者交流群:①群:446310206 ②群:426087546 7 | // 8 | 9 | #import "JQImageCropperViewController.h" 10 | 11 | #define SCALE_FRAME_Y 100.0f 12 | #define BOUNDCE_DURATION 0.3f 13 | 14 | @interface JQImageCropperViewController () 15 | 16 | @property (nonatomic, retain) UIImage *originalImage; 17 | @property (nonatomic, retain) UIImage *editedImage; 18 | 19 | @property (nonatomic, retain) UIImageView *showImgView; 20 | @property (nonatomic, retain) UIView *overlayView; 21 | @property (nonatomic, retain) UIView *ratioView; 22 | 23 | @property (nonatomic, assign) CGRect oldFrame; 24 | @property (nonatomic, assign) CGRect largeFrame; 25 | @property (nonatomic, assign) CGFloat limitRatio; 26 | 27 | @property (nonatomic, assign) CGRect latestFrame; 28 | 29 | @end 30 | 31 | @implementation JQImageCropperViewController 32 | 33 | #pragma mark - LifeCycle 34 | 35 | - (id)initWithImage:(UIImage *)originalImage cropFrame:(CGRect)cropFrame limitScaleRatio:(NSInteger)limitRatio { 36 | if (self = [super init]) 37 | { 38 | self.cropFrame = cropFrame; 39 | self.limitRatio = limitRatio; 40 | self.originalImage = originalImage; 41 | } 42 | return self; 43 | } 44 | 45 | - (void)viewDidLoad{ 46 | [super viewDidLoad]; 47 | [self initSubView]; 48 | [self initControlBtn]; 49 | [self addGestureRecognizers]; 50 | } 51 | 52 | - (void)dealloc { 53 | self.originalImage = nil; 54 | self.showImgView = nil; 55 | self.editedImage = nil; 56 | self.overlayView = nil; 57 | self.ratioView = nil; 58 | } 59 | 60 | #pragma mark - Private 61 | 62 | - (void)initSubView{ 63 | self.showImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 240)]; 64 | [self.showImgView setMultipleTouchEnabled:YES]; 65 | [self.showImgView setUserInteractionEnabled:YES]; 66 | [self.showImgView setImage:self.originalImage]; 67 | 68 | // scale to fit the screen 69 | CGFloat oriWidth = self.cropFrame.size.width; 70 | CGFloat oriHeight = self.originalImage.size.height * (oriWidth / self.originalImage.size.width); 71 | CGFloat oriX = self.cropFrame.origin.x + (self.cropFrame.size.width - oriWidth) / 2; 72 | CGFloat oriY = self.cropFrame.origin.y + (self.cropFrame.size.height - oriHeight) / 2; 73 | self.oldFrame = CGRectMake(oriX, oriY, oriWidth, oriHeight); 74 | self.latestFrame = self.oldFrame; 75 | self.showImgView.frame = self.oldFrame; 76 | self.largeFrame = CGRectMake(0, 0, self.limitRatio * self.oldFrame.size.width, self.limitRatio * self.oldFrame.size.height); 77 | 78 | [self.view addSubview:self.showImgView]; 79 | 80 | self.overlayView = [[UIView alloc] initWithFrame:self.view.bounds]; 81 | self.overlayView.alpha = .5f; 82 | self.overlayView.backgroundColor = [UIColor blackColor]; 83 | self.overlayView.userInteractionEnabled = NO; 84 | self.overlayView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 85 | [self.view addSubview:self.overlayView]; 86 | 87 | self.ratioView = [[UIView alloc] initWithFrame:self.cropFrame]; 88 | self.ratioView.layer.borderColor = [UIColor whiteColor].CGColor; 89 | self.ratioView.layer.borderWidth = 1.0f; 90 | self.ratioView.autoresizingMask = UIViewAutoresizingNone; 91 | [self.view addSubview:self.ratioView]; 92 | [self overlayClipping]; 93 | [self.view setBackgroundColor:[UIColor blackColor]]; 94 | } 95 | 96 | - (void)overlayClipping{ 97 | CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; 98 | CGMutablePathRef path = CGPathCreateMutable(); 99 | // Left side of the ratio view 100 | CGPathAddRect(path, nil, CGRectMake(0, 0,self.cropFrame.origin.x,self.overlayView.frame.size.height)); 101 | // Right side of the ratio view 102 | CGPathAddRect(path, nil, CGRectMake(self.cropFrame.origin.x + self.ratioView.frame.size.width, 103 | 0, 104 | self.overlayView.frame.size.width - self.ratioView.frame.origin.x - self.cropFrame.size.width, 105 | self.overlayView.frame.size.height)); 106 | // Top side of the ratio view 107 | CGPathAddRect(path, nil, CGRectMake(0, 0, 108 | self.overlayView.frame.size.width, 109 | self.cropFrame.origin.y)); 110 | // Bottom side of the ratio view 111 | CGPathAddRect(path, nil, CGRectMake(0, 112 | self.cropFrame.origin.y + self.ratioView.frame.size.height, 113 | self.overlayView.frame.size.width, 114 | self.overlayView.frame.size.height - self.ratioView.frame.origin.y + self.cropFrame.size.height)); 115 | maskLayer.path = path; 116 | self.overlayView.layer.mask = maskLayer; 117 | CGPathRelease(path); 118 | } 119 | 120 | - (void)initControlBtn { 121 | UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 70.0f, self.view.frame.size.width, 70)]; 122 | backView.backgroundColor = [UIColor colorWithRed:40/255.f green:40/255.f blue:40/255.f alpha:0.8]; 123 | 124 | UIButton *cancelBtn = [self buttonWithTitle:@"取消"]; 125 | cancelBtn.frame = CGRectMake(0, 10, 100, 50); 126 | [cancelBtn addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside]; 127 | [backView addSubview:cancelBtn]; 128 | 129 | UIButton *confirmBtn = [self buttonWithTitle:@"确定"]; 130 | confirmBtn.frame = CGRectMake(self.view.frame.size.width - 100.0f, 10, 100, 50); 131 | [confirmBtn addTarget:self action:@selector(confirm:) forControlEvents:UIControlEventTouchUpInside]; 132 | [backView addSubview:confirmBtn]; 133 | [self.view addSubview:backView]; 134 | } 135 | - (UIButton *)buttonWithTitle:(NSString *)title{ 136 | UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 137 | button.backgroundColor = [UIColor clearColor]; 138 | [button setTitle:title forState:UIControlStateNormal]; 139 | [button.titleLabel setFont:[UIFont boldSystemFontOfSize:18.0f]]; 140 | [button.titleLabel setTextAlignment:NSTextAlignmentCenter]; 141 | [button.titleLabel setLineBreakMode:NSLineBreakByWordWrapping]; 142 | [button.titleLabel setNumberOfLines:0]; 143 | [button setTitleEdgeInsets:UIEdgeInsetsMake(5.0f, 5.0f, 5.0f, 5.0f)]; 144 | return button; 145 | } 146 | #pragma mark - Action 147 | 148 | - (void)confirm:(id)sender { 149 | self.submitblock(self, [self getSubImage]); 150 | } 151 | 152 | - (void)cancel:(id)sender { 153 | self.cancelblock(self); 154 | } 155 | 156 | #pragma mark - Gestures 157 | // register all gestures 158 | - (void) addGestureRecognizers{ 159 | // add pinch gesture 160 | UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchView:)]; 161 | [self.view addGestureRecognizer:pinchGestureRecognizer]; 162 | 163 | // add pan gesture 164 | UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panView:)]; 165 | [self.view addGestureRecognizer:panGestureRecognizer]; 166 | } 167 | 168 | // pinch gesture handler 169 | - (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer{ 170 | UIView *view = self.showImgView; 171 | if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) { 172 | view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale); 173 | pinchGestureRecognizer.scale = 1; 174 | } 175 | else if (pinchGestureRecognizer.state == UIGestureRecognizerStateEnded) { 176 | CGRect newFrame = self.showImgView.frame; 177 | newFrame = [self handleScaleOverflow:newFrame]; 178 | newFrame = [self handleBorderOverflow:newFrame]; 179 | [UIView animateWithDuration:BOUNDCE_DURATION animations:^{ 180 | self.showImgView.frame = newFrame; 181 | self.latestFrame = newFrame; 182 | }]; 183 | } 184 | } 185 | 186 | // pan gesture handler 187 | - (void) panView:(UIPanGestureRecognizer *)panGestureRecognizer{ 188 | UIView *view = self.showImgView; 189 | if (panGestureRecognizer.state == UIGestureRecognizerStateBegan || panGestureRecognizer.state == UIGestureRecognizerStateChanged) { 190 | // calculate accelerator 191 | CGFloat absCenterX = self.cropFrame.origin.x + self.cropFrame.size.width / 2; 192 | CGFloat absCenterY = self.cropFrame.origin.y + self.cropFrame.size.height / 2; 193 | CGFloat scaleRatio = self.showImgView.frame.size.width / self.cropFrame.size.width; 194 | CGFloat acceleratorX = 1 - ABS(absCenterX - view.center.x) / (scaleRatio * absCenterX); 195 | CGFloat acceleratorY = 1 - ABS(absCenterY - view.center.y) / (scaleRatio * absCenterY); 196 | CGPoint translation = [panGestureRecognizer translationInView:view.superview]; 197 | [view setCenter:(CGPoint){view.center.x + translation.x * acceleratorX, view.center.y + translation.y * acceleratorY}]; 198 | [panGestureRecognizer setTranslation:CGPointZero inView:view.superview]; 199 | } 200 | else if (panGestureRecognizer.state == UIGestureRecognizerStateEnded) { 201 | // bounce to original frame 202 | CGRect newFrame = self.showImgView.frame; 203 | newFrame = [self handleBorderOverflow:newFrame]; 204 | [UIView animateWithDuration:BOUNDCE_DURATION animations:^{ 205 | self.showImgView.frame = newFrame; 206 | self.latestFrame = newFrame; 207 | }]; 208 | } 209 | } 210 | #pragma mark - Handle 211 | 212 | - (CGRect)handleScaleOverflow:(CGRect)newFrame { 213 | // bounce to original frame 214 | CGPoint oriCenter = CGPointMake(newFrame.origin.x + newFrame.size.width/2, newFrame.origin.y + newFrame.size.height/2); 215 | if (newFrame.size.width < self.oldFrame.size.width) { 216 | newFrame = self.oldFrame; 217 | } 218 | if (newFrame.size.width > self.largeFrame.size.width) { 219 | newFrame = self.largeFrame; 220 | } 221 | newFrame.origin.x = oriCenter.x - newFrame.size.width/2; 222 | newFrame.origin.y = oriCenter.y - newFrame.size.height/2; 223 | return newFrame; 224 | } 225 | 226 | - (CGRect)handleBorderOverflow:(CGRect)newFrame { 227 | // horizontally 228 | if (newFrame.origin.x > self.cropFrame.origin.x) newFrame.origin.x = self.cropFrame.origin.x; 229 | if (CGRectGetMaxX(newFrame) < self.cropFrame.size.width) newFrame.origin.x = self.cropFrame.size.width - newFrame.size.width; 230 | // vertically 231 | if (newFrame.origin.y > self.cropFrame.origin.y) newFrame.origin.y = self.cropFrame.origin.y; 232 | if (CGRectGetMaxY(newFrame) < self.cropFrame.origin.y + self.cropFrame.size.height) { 233 | newFrame.origin.y = self.cropFrame.origin.y + self.cropFrame.size.height - newFrame.size.height; 234 | } 235 | // adapt horizontally rectangle 236 | if (self.showImgView.frame.size.width > self.showImgView.frame.size.height && newFrame.size.height <= self.cropFrame.size.height) { 237 | newFrame.origin.y = self.cropFrame.origin.y + (self.cropFrame.size.height - newFrame.size.height) / 2; 238 | } 239 | return newFrame; 240 | } 241 | 242 | -(UIImage *)getSubImage{ 243 | CGRect squareFrame = self.cropFrame; 244 | CGFloat scaleRatio = self.latestFrame.size.width / self.originalImage.size.width; 245 | CGFloat x = (squareFrame.origin.x - self.latestFrame.origin.x) / scaleRatio; 246 | CGFloat y = (squareFrame.origin.y - self.latestFrame.origin.y) / scaleRatio; 247 | CGFloat w = squareFrame.size.width / scaleRatio; 248 | CGFloat h = squareFrame.size.height / scaleRatio; 249 | if (self.latestFrame.size.width < self.cropFrame.size.width) { 250 | CGFloat newW = self.originalImage.size.width; 251 | CGFloat newH = newW * (self.cropFrame.size.height / self.cropFrame.size.width); 252 | x = 0; y = y + (h - newH) / 2; 253 | w = newH; h = newH; 254 | } 255 | if (self.latestFrame.size.height < self.cropFrame.size.height) { 256 | CGFloat newH = self.originalImage.size.height; 257 | CGFloat newW = newH * (self.cropFrame.size.width / self.cropFrame.size.height); 258 | x = x + (w - newW) / 2; y = 0; 259 | w = newH; h = newH; 260 | } 261 | CGRect myImageRect = CGRectMake(x, y, w, h); 262 | CGImageRef imageRef = self.originalImage.CGImage; 263 | CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, myImageRect); 264 | CGSize size; 265 | size.width = myImageRect.size.width; 266 | size.height = myImageRect.size.height; 267 | UIGraphicsBeginImageContext(size); 268 | CGContextRef context = UIGraphicsGetCurrentContext(); 269 | CGContextDrawImage(context, myImageRect, subImageRef); 270 | UIImage* smallImage = [UIImage imageWithCGImage:subImageRef]; 271 | UIGraphicsEndImageContext(); 272 | CGImageRelease(subImageRef); 273 | return smallImage; 274 | } 275 | 276 | @end 277 | -------------------------------------------------------------------------------- /JQImagePicker/JQImagePicker.h: -------------------------------------------------------------------------------- 1 | // 2 | // JQImagePicker.h 3 | // 4 | // Created by 韩俊强 on 16/7/6. 5 | // Copyright © 2016年 HaRi. All rights reserved. 6 | // 手机加iOS开发者交流群:①群:446310206 ②群:426087546 7 | // 8 | 9 | #import 10 | #import 11 | typedef NS_ENUM(NSInteger,ImagePickerType){ 12 | ImagePickerCamera = 0, 13 | ImagePickerPhoto = 1 14 | }; 15 | @class JQImagePicker; 16 | @protocol JQImagePickerDelegate 17 | 18 | - (void)imagePicker:(JQImagePicker *)imagePicker didFinished:(UIImage *)editedImage; 19 | - (void)imagePickerDidCancel:(JQImagePicker *)imagePicker; 20 | @end 21 | @interface JQImagePicker : NSObject 22 | + (instancetype) sharedInstance; 23 | //delegate 24 | @property (nonatomic, assign) id delegate; 25 | //choose original image 26 | - (void)showOriginalImagePickerWithType:(ImagePickerType)type InViewController:(UIViewController *)viewController; 27 | //Custom cut. Cutting box's scale(height/Width) 0~1.5 default is 1 28 | - (void)showImagePickerWithType:(ImagePickerType)type InViewController:(UIViewController *)viewController Scale:(double)scale; 29 | @end 30 | -------------------------------------------------------------------------------- /JQImagePicker/JQImagePicker.m: -------------------------------------------------------------------------------- 1 | // 2 | // JQImagePicker.m 3 | // 4 | // Created by 韩俊强 on 16/7/6. 5 | // Copyright © 2016年 HaRi. All rights reserved. 6 | // 手机加iOS开发者交流群:①群:446310206 ②群:426087546 7 | // 8 | 9 | #import "JQImagePicker.h" 10 | #import "JQImageCropperViewController.h" 11 | #define ScreenWidth CGRectGetWidth([UIScreen mainScreen].bounds) 12 | #define ScreenHeight CGRectGetHeight([UIScreen mainScreen].bounds) 13 | @interface JQImagePicker(){ 14 | BOOL isScale; 15 | double _scale; 16 | } 17 | @property (nonatomic, strong) UIImagePickerController *imagePickerController; 18 | @property (nonatomic, strong) JQImageCropperViewController *imageCropperController; 19 | @end 20 | @implementation JQImagePicker 21 | #pragma mark -- 单例 -- 22 | + (instancetype)sharedInstance{ 23 | static dispatch_once_t ETToken; 24 | static JQImagePicker *sharedInstance = nil; 25 | dispatch_once(&ETToken, ^{ 26 | sharedInstance = [[JQImagePicker alloc] init]; 27 | }); 28 | return sharedInstance; 29 | } 30 | - (void)showOriginalImagePickerWithType:(ImagePickerType)type InViewController:(UIViewController *)viewController{ 31 | if (type == ImagePickerCamera) { 32 | #if TARGET_IPHONE_SIMULATOR //模拟器 33 | NSLog(@"请使用真机测试"); 34 | return; 35 | #elif TARGET_OS_IPHONE //真机 36 | self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 37 | #endif 38 | 39 | }else{ 40 | self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 41 | } 42 | isScale = NO; 43 | self.imagePickerController.allowsEditing = YES; 44 | [viewController presentViewController:_imagePickerController animated:YES completion:nil]; 45 | } 46 | - (void)showImagePickerWithType:(ImagePickerType)type InViewController:(UIViewController *)viewController Scale:(double)scale{ 47 | if (type == ImagePickerCamera) { 48 | #if TARGET_IPHONE_SIMULATOR //模拟器 49 | NSLog(@"请使用真机测试"); 50 | return; 51 | #elif TARGET_OS_IPHONE //真机 52 | self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 53 | #endif 54 | }else{ 55 | self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 56 | } 57 | self.imagePickerController.allowsEditing = NO; 58 | isScale = YES; 59 | if(scale>0 &&scale<=1.5){ 60 | _scale = scale; 61 | }else{ 62 | _scale = 1; 63 | } 64 | 65 | [viewController presentViewController:_imagePickerController animated:YES completion:nil]; 66 | } 67 | #pragma mark - UIImagePickerControllerDelegate 68 | - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 69 | 70 | UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage]; 71 | UIImageOrientation imageOrientation=image.imageOrientation; 72 | if(imageOrientation!=UIImageOrientationUp){ 73 | // Adjust picture Angle 74 | UIGraphicsBeginImageContext(image.size); 75 | [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; 76 | image = UIGraphicsGetImageFromCurrentImageContext(); 77 | UIGraphicsEndImageContext(); 78 | 79 | } 80 | if (isScale) { 81 | self.imageCropperController = [[JQImageCropperViewController alloc] initWithImage:image cropFrame:CGRectMake(0, (ScreenHeight-ScreenWidth*_scale)/2, ScreenWidth, ScreenWidth*_scale) limitScaleRatio:5]; 82 | __weak typeof(self) weakself = self; 83 | [_imageCropperController setSubmitblock:^(UIViewController *viewController , UIImage *image) { 84 | [viewController dismissViewControllerAnimated:YES completion:nil]; 85 | if (weakself.delegate && [weakself.delegate respondsToSelector:@selector(imagePicker:didFinished:)]) { 86 | [weakself.delegate imagePicker:weakself didFinished:image]; 87 | } 88 | }]; 89 | [_imageCropperController setCancelblock:^(UIViewController *viewController){ 90 | UIImagePickerController *picker = (UIImagePickerController *)viewController.navigationController; 91 | if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) { 92 | [viewController.navigationController dismissViewControllerAnimated:YES completion:nil]; 93 | }else{ 94 | [viewController.navigationController popViewControllerAnimated:YES]; 95 | } 96 | }]; 97 | [picker pushViewController:self.imageCropperController animated:YES]; 98 | }else{ 99 | [picker dismissViewControllerAnimated:YES completion:^{}]; 100 | if (self.delegate && [self.delegate respondsToSelector:@selector(imagePicker:didFinished:)]) { 101 | [self.delegate imagePicker:self didFinished:image]; 102 | } 103 | } 104 | 105 | } 106 | - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 107 | { 108 | [picker dismissViewControllerAnimated:YES completion:^{}]; 109 | if (self.delegate && [self.delegate respondsToSelector:@selector(imagePickerDidCancel:)]) { 110 | [self.delegate imagePickerDidCancel:self]; 111 | } 112 | } 113 | #pragma mark - Getters 114 | - (UIImagePickerController *)imagePickerController{ 115 | if (!_imagePickerController) { 116 | _imagePickerController = [[UIImagePickerController alloc] init]; 117 | _imagePickerController.delegate = self; 118 | _imagePickerController.allowsEditing = NO; 119 | } 120 | return _imagePickerController; 121 | } 122 | @end 123 | -------------------------------------------------------------------------------- /JQImagePickerDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 47ED09C71F6921C80069EB5F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 47ED09C61F6921C80069EB5F /* main.m */; }; 11 | 47ED09CA1F6921C80069EB5F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 47ED09C91F6921C80069EB5F /* AppDelegate.m */; }; 12 | 47ED09CD1F6921C80069EB5F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 47ED09CC1F6921C80069EB5F /* ViewController.m */; }; 13 | 47ED09D01F6921C80069EB5F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 47ED09CE1F6921C80069EB5F /* Main.storyboard */; }; 14 | 47ED09D21F6921C80069EB5F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 47ED09D11F6921C80069EB5F /* Assets.xcassets */; }; 15 | 47ED09D51F6921C80069EB5F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 47ED09D31F6921C80069EB5F /* LaunchScreen.storyboard */; }; 16 | 47ED09E01F6921C80069EB5F /* JQImagePickerDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 47ED09DF1F6921C80069EB5F /* JQImagePickerDemoTests.m */; }; 17 | 47ED09EB1F6921C80069EB5F /* JQImagePickerDemoUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 47ED09EA1F6921C80069EB5F /* JQImagePickerDemoUITests.m */; }; 18 | 47ED09FD1F6922060069EB5F /* JQImageCropperViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 47ED09FA1F6922060069EB5F /* JQImageCropperViewController.m */; }; 19 | 47ED09FE1F6922060069EB5F /* JQImagePicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 47ED09FC1F6922060069EB5F /* JQImagePicker.m */; }; 20 | 47ED0A011F692C130069EB5F /* UIImage+GCAdd.m in Sources */ = {isa = PBXBuildFile; fileRef = 47ED0A001F692C130069EB5F /* UIImage+GCAdd.m */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 47ED09DC1F6921C80069EB5F /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 47ED09BA1F6921C80069EB5F /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 47ED09C11F6921C80069EB5F; 29 | remoteInfo = JQImagePickerDemo; 30 | }; 31 | 47ED09E71F6921C80069EB5F /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = 47ED09BA1F6921C80069EB5F /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = 47ED09C11F6921C80069EB5F; 36 | remoteInfo = JQImagePickerDemo; 37 | }; 38 | /* End PBXContainerItemProxy section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | 47ED09C21F6921C80069EB5F /* JQImagePickerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JQImagePickerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | 47ED09C61F6921C80069EB5F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 43 | 47ED09C81F6921C80069EB5F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 44 | 47ED09C91F6921C80069EB5F /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 45 | 47ED09CB1F6921C80069EB5F /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 46 | 47ED09CC1F6921C80069EB5F /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 47 | 47ED09CF1F6921C80069EB5F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 48 | 47ED09D11F6921C80069EB5F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 49 | 47ED09D41F6921C80069EB5F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 50 | 47ED09D61F6921C80069EB5F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | 47ED09DB1F6921C80069EB5F /* JQImagePickerDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JQImagePickerDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 52 | 47ED09DF1F6921C80069EB5F /* JQImagePickerDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JQImagePickerDemoTests.m; sourceTree = ""; }; 53 | 47ED09E11F6921C80069EB5F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | 47ED09E61F6921C80069EB5F /* JQImagePickerDemoUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JQImagePickerDemoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | 47ED09EA1F6921C80069EB5F /* JQImagePickerDemoUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JQImagePickerDemoUITests.m; sourceTree = ""; }; 56 | 47ED09EC1F6921C80069EB5F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | 47ED09F91F6922060069EB5F /* JQImageCropperViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JQImageCropperViewController.h; sourceTree = ""; }; 58 | 47ED09FA1F6922060069EB5F /* JQImageCropperViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JQImageCropperViewController.m; sourceTree = ""; }; 59 | 47ED09FB1F6922060069EB5F /* JQImagePicker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JQImagePicker.h; sourceTree = ""; }; 60 | 47ED09FC1F6922060069EB5F /* JQImagePicker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JQImagePicker.m; sourceTree = ""; }; 61 | 47ED09FF1F692C130069EB5F /* UIImage+GCAdd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+GCAdd.h"; sourceTree = ""; }; 62 | 47ED0A001F692C130069EB5F /* UIImage+GCAdd.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+GCAdd.m"; sourceTree = ""; }; 63 | /* End PBXFileReference section */ 64 | 65 | /* Begin PBXFrameworksBuildPhase section */ 66 | 47ED09BF1F6921C80069EB5F /* Frameworks */ = { 67 | isa = PBXFrameworksBuildPhase; 68 | buildActionMask = 2147483647; 69 | files = ( 70 | ); 71 | runOnlyForDeploymentPostprocessing = 0; 72 | }; 73 | 47ED09D81F6921C80069EB5F /* Frameworks */ = { 74 | isa = PBXFrameworksBuildPhase; 75 | buildActionMask = 2147483647; 76 | files = ( 77 | ); 78 | runOnlyForDeploymentPostprocessing = 0; 79 | }; 80 | 47ED09E31F6921C80069EB5F /* Frameworks */ = { 81 | isa = PBXFrameworksBuildPhase; 82 | buildActionMask = 2147483647; 83 | files = ( 84 | ); 85 | runOnlyForDeploymentPostprocessing = 0; 86 | }; 87 | /* End PBXFrameworksBuildPhase section */ 88 | 89 | /* Begin PBXGroup section */ 90 | 47ED09B91F6921C80069EB5F = { 91 | isa = PBXGroup; 92 | children = ( 93 | 47ED09F81F6922060069EB5F /* JQImagePicker */, 94 | 47ED09C41F6921C80069EB5F /* JQImagePickerDemo */, 95 | 47ED09DE1F6921C80069EB5F /* JQImagePickerDemoTests */, 96 | 47ED09E91F6921C80069EB5F /* JQImagePickerDemoUITests */, 97 | 47ED09C31F6921C80069EB5F /* Products */, 98 | ); 99 | sourceTree = ""; 100 | }; 101 | 47ED09C31F6921C80069EB5F /* Products */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 47ED09C21F6921C80069EB5F /* JQImagePickerDemo.app */, 105 | 47ED09DB1F6921C80069EB5F /* JQImagePickerDemoTests.xctest */, 106 | 47ED09E61F6921C80069EB5F /* JQImagePickerDemoUITests.xctest */, 107 | ); 108 | name = Products; 109 | sourceTree = ""; 110 | }; 111 | 47ED09C41F6921C80069EB5F /* JQImagePickerDemo */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | 47ED09FF1F692C130069EB5F /* UIImage+GCAdd.h */, 115 | 47ED0A001F692C130069EB5F /* UIImage+GCAdd.m */, 116 | 47ED09C81F6921C80069EB5F /* AppDelegate.h */, 117 | 47ED09C91F6921C80069EB5F /* AppDelegate.m */, 118 | 47ED09CB1F6921C80069EB5F /* ViewController.h */, 119 | 47ED09CC1F6921C80069EB5F /* ViewController.m */, 120 | 47ED09CE1F6921C80069EB5F /* Main.storyboard */, 121 | 47ED09D11F6921C80069EB5F /* Assets.xcassets */, 122 | 47ED09D31F6921C80069EB5F /* LaunchScreen.storyboard */, 123 | 47ED09D61F6921C80069EB5F /* Info.plist */, 124 | 47ED09C51F6921C80069EB5F /* Supporting Files */, 125 | ); 126 | path = JQImagePickerDemo; 127 | sourceTree = ""; 128 | }; 129 | 47ED09C51F6921C80069EB5F /* Supporting Files */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | 47ED09C61F6921C80069EB5F /* main.m */, 133 | ); 134 | name = "Supporting Files"; 135 | sourceTree = ""; 136 | }; 137 | 47ED09DE1F6921C80069EB5F /* JQImagePickerDemoTests */ = { 138 | isa = PBXGroup; 139 | children = ( 140 | 47ED09DF1F6921C80069EB5F /* JQImagePickerDemoTests.m */, 141 | 47ED09E11F6921C80069EB5F /* Info.plist */, 142 | ); 143 | path = JQImagePickerDemoTests; 144 | sourceTree = ""; 145 | }; 146 | 47ED09E91F6921C80069EB5F /* JQImagePickerDemoUITests */ = { 147 | isa = PBXGroup; 148 | children = ( 149 | 47ED09EA1F6921C80069EB5F /* JQImagePickerDemoUITests.m */, 150 | 47ED09EC1F6921C80069EB5F /* Info.plist */, 151 | ); 152 | path = JQImagePickerDemoUITests; 153 | sourceTree = ""; 154 | }; 155 | 47ED09F81F6922060069EB5F /* JQImagePicker */ = { 156 | isa = PBXGroup; 157 | children = ( 158 | 47ED09F91F6922060069EB5F /* JQImageCropperViewController.h */, 159 | 47ED09FA1F6922060069EB5F /* JQImageCropperViewController.m */, 160 | 47ED09FB1F6922060069EB5F /* JQImagePicker.h */, 161 | 47ED09FC1F6922060069EB5F /* JQImagePicker.m */, 162 | ); 163 | path = JQImagePicker; 164 | sourceTree = ""; 165 | }; 166 | /* End PBXGroup section */ 167 | 168 | /* Begin PBXNativeTarget section */ 169 | 47ED09C11F6921C80069EB5F /* JQImagePickerDemo */ = { 170 | isa = PBXNativeTarget; 171 | buildConfigurationList = 47ED09EF1F6921C80069EB5F /* Build configuration list for PBXNativeTarget "JQImagePickerDemo" */; 172 | buildPhases = ( 173 | 47ED09BE1F6921C80069EB5F /* Sources */, 174 | 47ED09BF1F6921C80069EB5F /* Frameworks */, 175 | 47ED09C01F6921C80069EB5F /* Resources */, 176 | ); 177 | buildRules = ( 178 | ); 179 | dependencies = ( 180 | ); 181 | name = JQImagePickerDemo; 182 | productName = JQImagePickerDemo; 183 | productReference = 47ED09C21F6921C80069EB5F /* JQImagePickerDemo.app */; 184 | productType = "com.apple.product-type.application"; 185 | }; 186 | 47ED09DA1F6921C80069EB5F /* JQImagePickerDemoTests */ = { 187 | isa = PBXNativeTarget; 188 | buildConfigurationList = 47ED09F21F6921C80069EB5F /* Build configuration list for PBXNativeTarget "JQImagePickerDemoTests" */; 189 | buildPhases = ( 190 | 47ED09D71F6921C80069EB5F /* Sources */, 191 | 47ED09D81F6921C80069EB5F /* Frameworks */, 192 | 47ED09D91F6921C80069EB5F /* Resources */, 193 | ); 194 | buildRules = ( 195 | ); 196 | dependencies = ( 197 | 47ED09DD1F6921C80069EB5F /* PBXTargetDependency */, 198 | ); 199 | name = JQImagePickerDemoTests; 200 | productName = JQImagePickerDemoTests; 201 | productReference = 47ED09DB1F6921C80069EB5F /* JQImagePickerDemoTests.xctest */; 202 | productType = "com.apple.product-type.bundle.unit-test"; 203 | }; 204 | 47ED09E51F6921C80069EB5F /* JQImagePickerDemoUITests */ = { 205 | isa = PBXNativeTarget; 206 | buildConfigurationList = 47ED09F51F6921C80069EB5F /* Build configuration list for PBXNativeTarget "JQImagePickerDemoUITests" */; 207 | buildPhases = ( 208 | 47ED09E21F6921C80069EB5F /* Sources */, 209 | 47ED09E31F6921C80069EB5F /* Frameworks */, 210 | 47ED09E41F6921C80069EB5F /* Resources */, 211 | ); 212 | buildRules = ( 213 | ); 214 | dependencies = ( 215 | 47ED09E81F6921C80069EB5F /* PBXTargetDependency */, 216 | ); 217 | name = JQImagePickerDemoUITests; 218 | productName = JQImagePickerDemoUITests; 219 | productReference = 47ED09E61F6921C80069EB5F /* JQImagePickerDemoUITests.xctest */; 220 | productType = "com.apple.product-type.bundle.ui-testing"; 221 | }; 222 | /* End PBXNativeTarget section */ 223 | 224 | /* Begin PBXProject section */ 225 | 47ED09BA1F6921C80069EB5F /* Project object */ = { 226 | isa = PBXProject; 227 | attributes = { 228 | LastUpgradeCheck = 0830; 229 | ORGANIZATIONNAME = HaRi; 230 | TargetAttributes = { 231 | 47ED09C11F6921C80069EB5F = { 232 | CreatedOnToolsVersion = 8.3.3; 233 | DevelopmentTeam = NXY5JXSFY9; 234 | ProvisioningStyle = Automatic; 235 | }; 236 | 47ED09DA1F6921C80069EB5F = { 237 | CreatedOnToolsVersion = 8.3.3; 238 | DevelopmentTeam = WTB2BKP7UZ; 239 | ProvisioningStyle = Automatic; 240 | TestTargetID = 47ED09C11F6921C80069EB5F; 241 | }; 242 | 47ED09E51F6921C80069EB5F = { 243 | CreatedOnToolsVersion = 8.3.3; 244 | DevelopmentTeam = WTB2BKP7UZ; 245 | ProvisioningStyle = Automatic; 246 | TestTargetID = 47ED09C11F6921C80069EB5F; 247 | }; 248 | }; 249 | }; 250 | buildConfigurationList = 47ED09BD1F6921C80069EB5F /* Build configuration list for PBXProject "JQImagePickerDemo" */; 251 | compatibilityVersion = "Xcode 3.2"; 252 | developmentRegion = English; 253 | hasScannedForEncodings = 0; 254 | knownRegions = ( 255 | English, 256 | en, 257 | Base, 258 | ); 259 | mainGroup = 47ED09B91F6921C80069EB5F; 260 | productRefGroup = 47ED09C31F6921C80069EB5F /* Products */; 261 | projectDirPath = ""; 262 | projectRoot = ""; 263 | targets = ( 264 | 47ED09C11F6921C80069EB5F /* JQImagePickerDemo */, 265 | 47ED09DA1F6921C80069EB5F /* JQImagePickerDemoTests */, 266 | 47ED09E51F6921C80069EB5F /* JQImagePickerDemoUITests */, 267 | ); 268 | }; 269 | /* End PBXProject section */ 270 | 271 | /* Begin PBXResourcesBuildPhase section */ 272 | 47ED09C01F6921C80069EB5F /* Resources */ = { 273 | isa = PBXResourcesBuildPhase; 274 | buildActionMask = 2147483647; 275 | files = ( 276 | 47ED09D51F6921C80069EB5F /* LaunchScreen.storyboard in Resources */, 277 | 47ED09D21F6921C80069EB5F /* Assets.xcassets in Resources */, 278 | 47ED09D01F6921C80069EB5F /* Main.storyboard in Resources */, 279 | ); 280 | runOnlyForDeploymentPostprocessing = 0; 281 | }; 282 | 47ED09D91F6921C80069EB5F /* Resources */ = { 283 | isa = PBXResourcesBuildPhase; 284 | buildActionMask = 2147483647; 285 | files = ( 286 | ); 287 | runOnlyForDeploymentPostprocessing = 0; 288 | }; 289 | 47ED09E41F6921C80069EB5F /* Resources */ = { 290 | isa = PBXResourcesBuildPhase; 291 | buildActionMask = 2147483647; 292 | files = ( 293 | ); 294 | runOnlyForDeploymentPostprocessing = 0; 295 | }; 296 | /* End PBXResourcesBuildPhase section */ 297 | 298 | /* Begin PBXSourcesBuildPhase section */ 299 | 47ED09BE1F6921C80069EB5F /* Sources */ = { 300 | isa = PBXSourcesBuildPhase; 301 | buildActionMask = 2147483647; 302 | files = ( 303 | 47ED09CD1F6921C80069EB5F /* ViewController.m in Sources */, 304 | 47ED09FD1F6922060069EB5F /* JQImageCropperViewController.m in Sources */, 305 | 47ED09FE1F6922060069EB5F /* JQImagePicker.m in Sources */, 306 | 47ED09CA1F6921C80069EB5F /* AppDelegate.m in Sources */, 307 | 47ED09C71F6921C80069EB5F /* main.m in Sources */, 308 | 47ED0A011F692C130069EB5F /* UIImage+GCAdd.m in Sources */, 309 | ); 310 | runOnlyForDeploymentPostprocessing = 0; 311 | }; 312 | 47ED09D71F6921C80069EB5F /* Sources */ = { 313 | isa = PBXSourcesBuildPhase; 314 | buildActionMask = 2147483647; 315 | files = ( 316 | 47ED09E01F6921C80069EB5F /* JQImagePickerDemoTests.m in Sources */, 317 | ); 318 | runOnlyForDeploymentPostprocessing = 0; 319 | }; 320 | 47ED09E21F6921C80069EB5F /* Sources */ = { 321 | isa = PBXSourcesBuildPhase; 322 | buildActionMask = 2147483647; 323 | files = ( 324 | 47ED09EB1F6921C80069EB5F /* JQImagePickerDemoUITests.m in Sources */, 325 | ); 326 | runOnlyForDeploymentPostprocessing = 0; 327 | }; 328 | /* End PBXSourcesBuildPhase section */ 329 | 330 | /* Begin PBXTargetDependency section */ 331 | 47ED09DD1F6921C80069EB5F /* PBXTargetDependency */ = { 332 | isa = PBXTargetDependency; 333 | target = 47ED09C11F6921C80069EB5F /* JQImagePickerDemo */; 334 | targetProxy = 47ED09DC1F6921C80069EB5F /* PBXContainerItemProxy */; 335 | }; 336 | 47ED09E81F6921C80069EB5F /* PBXTargetDependency */ = { 337 | isa = PBXTargetDependency; 338 | target = 47ED09C11F6921C80069EB5F /* JQImagePickerDemo */; 339 | targetProxy = 47ED09E71F6921C80069EB5F /* PBXContainerItemProxy */; 340 | }; 341 | /* End PBXTargetDependency section */ 342 | 343 | /* Begin PBXVariantGroup section */ 344 | 47ED09CE1F6921C80069EB5F /* Main.storyboard */ = { 345 | isa = PBXVariantGroup; 346 | children = ( 347 | 47ED09CF1F6921C80069EB5F /* Base */, 348 | ); 349 | name = Main.storyboard; 350 | sourceTree = ""; 351 | }; 352 | 47ED09D31F6921C80069EB5F /* LaunchScreen.storyboard */ = { 353 | isa = PBXVariantGroup; 354 | children = ( 355 | 47ED09D41F6921C80069EB5F /* Base */, 356 | ); 357 | name = LaunchScreen.storyboard; 358 | sourceTree = ""; 359 | }; 360 | /* End PBXVariantGroup section */ 361 | 362 | /* Begin XCBuildConfiguration section */ 363 | 47ED09ED1F6921C80069EB5F /* Debug */ = { 364 | isa = XCBuildConfiguration; 365 | buildSettings = { 366 | ALWAYS_SEARCH_USER_PATHS = NO; 367 | CLANG_ANALYZER_NONNULL = YES; 368 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 369 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 370 | CLANG_CXX_LIBRARY = "libc++"; 371 | CLANG_ENABLE_MODULES = YES; 372 | CLANG_ENABLE_OBJC_ARC = YES; 373 | CLANG_WARN_BOOL_CONVERSION = YES; 374 | CLANG_WARN_CONSTANT_CONVERSION = YES; 375 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 376 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 377 | CLANG_WARN_EMPTY_BODY = YES; 378 | CLANG_WARN_ENUM_CONVERSION = YES; 379 | CLANG_WARN_INFINITE_RECURSION = YES; 380 | CLANG_WARN_INT_CONVERSION = YES; 381 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 382 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 383 | CLANG_WARN_UNREACHABLE_CODE = YES; 384 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 385 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 386 | COPY_PHASE_STRIP = NO; 387 | DEBUG_INFORMATION_FORMAT = dwarf; 388 | ENABLE_STRICT_OBJC_MSGSEND = YES; 389 | ENABLE_TESTABILITY = YES; 390 | GCC_C_LANGUAGE_STANDARD = gnu99; 391 | GCC_DYNAMIC_NO_PIC = NO; 392 | GCC_NO_COMMON_BLOCKS = YES; 393 | GCC_OPTIMIZATION_LEVEL = 0; 394 | GCC_PREPROCESSOR_DEFINITIONS = ( 395 | "DEBUG=1", 396 | "$(inherited)", 397 | ); 398 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 399 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 400 | GCC_WARN_UNDECLARED_SELECTOR = YES; 401 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 402 | GCC_WARN_UNUSED_FUNCTION = YES; 403 | GCC_WARN_UNUSED_VARIABLE = YES; 404 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 405 | MTL_ENABLE_DEBUG_INFO = YES; 406 | ONLY_ACTIVE_ARCH = YES; 407 | SDKROOT = iphoneos; 408 | TARGETED_DEVICE_FAMILY = "1,2"; 409 | }; 410 | name = Debug; 411 | }; 412 | 47ED09EE1F6921C80069EB5F /* Release */ = { 413 | isa = XCBuildConfiguration; 414 | buildSettings = { 415 | ALWAYS_SEARCH_USER_PATHS = NO; 416 | CLANG_ANALYZER_NONNULL = YES; 417 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 418 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 419 | CLANG_CXX_LIBRARY = "libc++"; 420 | CLANG_ENABLE_MODULES = YES; 421 | CLANG_ENABLE_OBJC_ARC = YES; 422 | CLANG_WARN_BOOL_CONVERSION = YES; 423 | CLANG_WARN_CONSTANT_CONVERSION = YES; 424 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 425 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 426 | CLANG_WARN_EMPTY_BODY = YES; 427 | CLANG_WARN_ENUM_CONVERSION = YES; 428 | CLANG_WARN_INFINITE_RECURSION = YES; 429 | CLANG_WARN_INT_CONVERSION = YES; 430 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 431 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 432 | CLANG_WARN_UNREACHABLE_CODE = YES; 433 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 434 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 435 | COPY_PHASE_STRIP = NO; 436 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 437 | ENABLE_NS_ASSERTIONS = NO; 438 | ENABLE_STRICT_OBJC_MSGSEND = YES; 439 | GCC_C_LANGUAGE_STANDARD = gnu99; 440 | GCC_NO_COMMON_BLOCKS = YES; 441 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 442 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 443 | GCC_WARN_UNDECLARED_SELECTOR = YES; 444 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 445 | GCC_WARN_UNUSED_FUNCTION = YES; 446 | GCC_WARN_UNUSED_VARIABLE = YES; 447 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 448 | MTL_ENABLE_DEBUG_INFO = NO; 449 | SDKROOT = iphoneos; 450 | TARGETED_DEVICE_FAMILY = "1,2"; 451 | VALIDATE_PRODUCT = YES; 452 | }; 453 | name = Release; 454 | }; 455 | 47ED09F01F6921C80069EB5F /* Debug */ = { 456 | isa = XCBuildConfiguration; 457 | buildSettings = { 458 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 459 | DEVELOPMENT_TEAM = NXY5JXSFY9; 460 | INFOPLIST_FILE = JQImagePickerDemo/Info.plist; 461 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 462 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 463 | PRODUCT_BUNDLE_IDENTIFIER = HanJunqiang.JQImagePickerDemo; 464 | PRODUCT_NAME = "$(TARGET_NAME)"; 465 | }; 466 | name = Debug; 467 | }; 468 | 47ED09F11F6921C80069EB5F /* Release */ = { 469 | isa = XCBuildConfiguration; 470 | buildSettings = { 471 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 472 | DEVELOPMENT_TEAM = NXY5JXSFY9; 473 | INFOPLIST_FILE = JQImagePickerDemo/Info.plist; 474 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 475 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 476 | PRODUCT_BUNDLE_IDENTIFIER = HanJunqiang.JQImagePickerDemo; 477 | PRODUCT_NAME = "$(TARGET_NAME)"; 478 | }; 479 | name = Release; 480 | }; 481 | 47ED09F31F6921C80069EB5F /* Debug */ = { 482 | isa = XCBuildConfiguration; 483 | buildSettings = { 484 | BUNDLE_LOADER = "$(TEST_HOST)"; 485 | DEVELOPMENT_TEAM = WTB2BKP7UZ; 486 | INFOPLIST_FILE = JQImagePickerDemoTests/Info.plist; 487 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 488 | PRODUCT_BUNDLE_IDENTIFIER = HanJunqiang.JQImagePickerDemoTests; 489 | PRODUCT_NAME = "$(TARGET_NAME)"; 490 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JQImagePickerDemo.app/JQImagePickerDemo"; 491 | }; 492 | name = Debug; 493 | }; 494 | 47ED09F41F6921C80069EB5F /* Release */ = { 495 | isa = XCBuildConfiguration; 496 | buildSettings = { 497 | BUNDLE_LOADER = "$(TEST_HOST)"; 498 | DEVELOPMENT_TEAM = WTB2BKP7UZ; 499 | INFOPLIST_FILE = JQImagePickerDemoTests/Info.plist; 500 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 501 | PRODUCT_BUNDLE_IDENTIFIER = HanJunqiang.JQImagePickerDemoTests; 502 | PRODUCT_NAME = "$(TARGET_NAME)"; 503 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JQImagePickerDemo.app/JQImagePickerDemo"; 504 | }; 505 | name = Release; 506 | }; 507 | 47ED09F61F6921C80069EB5F /* Debug */ = { 508 | isa = XCBuildConfiguration; 509 | buildSettings = { 510 | DEVELOPMENT_TEAM = WTB2BKP7UZ; 511 | INFOPLIST_FILE = JQImagePickerDemoUITests/Info.plist; 512 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 513 | PRODUCT_BUNDLE_IDENTIFIER = HanJunqiang.JQImagePickerDemoUITests; 514 | PRODUCT_NAME = "$(TARGET_NAME)"; 515 | TEST_TARGET_NAME = JQImagePickerDemo; 516 | }; 517 | name = Debug; 518 | }; 519 | 47ED09F71F6921C80069EB5F /* Release */ = { 520 | isa = XCBuildConfiguration; 521 | buildSettings = { 522 | DEVELOPMENT_TEAM = WTB2BKP7UZ; 523 | INFOPLIST_FILE = JQImagePickerDemoUITests/Info.plist; 524 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 525 | PRODUCT_BUNDLE_IDENTIFIER = HanJunqiang.JQImagePickerDemoUITests; 526 | PRODUCT_NAME = "$(TARGET_NAME)"; 527 | TEST_TARGET_NAME = JQImagePickerDemo; 528 | }; 529 | name = Release; 530 | }; 531 | /* End XCBuildConfiguration section */ 532 | 533 | /* Begin XCConfigurationList section */ 534 | 47ED09BD1F6921C80069EB5F /* Build configuration list for PBXProject "JQImagePickerDemo" */ = { 535 | isa = XCConfigurationList; 536 | buildConfigurations = ( 537 | 47ED09ED1F6921C80069EB5F /* Debug */, 538 | 47ED09EE1F6921C80069EB5F /* Release */, 539 | ); 540 | defaultConfigurationIsVisible = 0; 541 | defaultConfigurationName = Release; 542 | }; 543 | 47ED09EF1F6921C80069EB5F /* Build configuration list for PBXNativeTarget "JQImagePickerDemo" */ = { 544 | isa = XCConfigurationList; 545 | buildConfigurations = ( 546 | 47ED09F01F6921C80069EB5F /* Debug */, 547 | 47ED09F11F6921C80069EB5F /* Release */, 548 | ); 549 | defaultConfigurationIsVisible = 0; 550 | defaultConfigurationName = Release; 551 | }; 552 | 47ED09F21F6921C80069EB5F /* Build configuration list for PBXNativeTarget "JQImagePickerDemoTests" */ = { 553 | isa = XCConfigurationList; 554 | buildConfigurations = ( 555 | 47ED09F31F6921C80069EB5F /* Debug */, 556 | 47ED09F41F6921C80069EB5F /* Release */, 557 | ); 558 | defaultConfigurationIsVisible = 0; 559 | defaultConfigurationName = Release; 560 | }; 561 | 47ED09F51F6921C80069EB5F /* Build configuration list for PBXNativeTarget "JQImagePickerDemoUITests" */ = { 562 | isa = XCConfigurationList; 563 | buildConfigurations = ( 564 | 47ED09F61F6921C80069EB5F /* Debug */, 565 | 47ED09F71F6921C80069EB5F /* Release */, 566 | ); 567 | defaultConfigurationIsVisible = 0; 568 | defaultConfigurationName = Release; 569 | }; 570 | /* End XCConfigurationList section */ 571 | }; 572 | rootObject = 47ED09BA1F6921C80069EB5F /* Project object */; 573 | } 574 | -------------------------------------------------------------------------------- /JQImagePickerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /JQImagePickerDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /JQImagePickerDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // JQImagePickerDemo 4 | // 5 | // Created by 韩俊强 on 2017/9/13. 6 | // Copyright © 2017年 HaRi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /JQImagePickerDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // JQImagePickerDemo 4 | // 5 | // Created by 韩俊强 on 2017/9/13. 6 | // Copyright © 2017年 HaRi. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /JQImagePickerDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /JQImagePickerDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /JQImagePickerDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 38 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /JQImagePickerDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | NSCameraUsageDescription 24 | 25 | NSPhotoLibraryUsageDescription 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeRight 39 | UIInterfaceOrientationLandscapeLeft 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /JQImagePickerDemo/UIImage+GCAdd.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+GCAdd.h 3 | // xizhi 4 | // 5 | // Created by 韩俊强 on 16/7/11. 6 | // Copyright © 2016年 HaRi. All rights reserved. 7 | // 手机加iOS开发者交流群:①群:446310206 ②群:426087546 8 | // 9 | 10 | #import 11 | NS_ASSUME_NONNULL_BEGIN 12 | @interface UIImage (GCAdd) 13 | 14 | /** 15 | Create and return a 1x1 point size image with the given color. 16 | 17 | @param color The color. 18 | */ 19 | + (nullable UIImage *)imageWithColor:(UIColor *)color; 20 | 21 | 22 | /** 23 | Create and return a pure color image with the given color and size. 24 | 25 | @param color The color. 26 | @param size New image's type. 27 | */ 28 | + (nullable UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size; 29 | 30 | 31 | /** 32 | Returns a new image which is scaled from this image. 33 | The image will be stretched as needed. 34 | 35 | @param size The new size to be scaled, values should be positive. 36 | 37 | @return The new image with the given size. 38 | */ 39 | - (nullable UIImage *)imageByResizeToSize:(CGSize)size; 40 | 41 | /** 42 | *返回中心拉伸的图片 43 | */ 44 | +(UIImage *)stretchedImageWithName:(NSString *)name; 45 | 46 | 47 | 48 | 49 | @end 50 | NS_ASSUME_NONNULL_END 51 | -------------------------------------------------------------------------------- /JQImagePickerDemo/UIImage+GCAdd.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+GCAdd.m 3 | // xizhi 4 | // 5 | // Created by 韩俊强 on 16/7/11. 6 | // Copyright © 2016年 HaRi. All rights reserved. 7 | // 手机加iOS开发者交流群:①群:446310206 ②群:426087546 8 | // 9 | 10 | #import "UIImage+GCAdd.h" 11 | 12 | @implementation UIImage (GCAdd) 13 | 14 | + (UIImage *)imageWithColor:(UIColor *)color { 15 | return [self imageWithColor:color size:CGSizeMake(1, 1)]; 16 | } 17 | 18 | + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size { 19 | if (!color || size.width <= 0 || size.height <= 0) return nil; 20 | CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height); 21 | UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0); 22 | CGContextRef context = UIGraphicsGetCurrentContext(); 23 | CGContextSetFillColorWithColor(context, color.CGColor); 24 | CGContextFillRect(context, rect); 25 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 26 | UIGraphicsEndImageContext(); 27 | return image; 28 | } 29 | 30 | 31 | - (UIImage *)imageByResizeToSize:(CGSize)size { 32 | if (size.width <= 0 || size.height <= 0) return nil; 33 | UIGraphicsBeginImageContextWithOptions(size, NO, self.scale); 34 | [self drawInRect:CGRectMake(0, 0, size.width, size.height)]; 35 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 36 | UIGraphicsEndImageContext(); 37 | return image; 38 | } 39 | 40 | +(UIImage *)stretchedImageWithName:(NSString *)name{ 41 | 42 | UIImage *image = [UIImage imageNamed:name]; 43 | int leftCap = image.size.width * 0.5; 44 | int topCap = image.size.height * 0.9; 45 | return [image stretchableImageWithLeftCapWidth:leftCap topCapHeight:topCap]; 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /JQImagePickerDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // JQImagePickerDemo 4 | // 5 | // Created by 韩俊强 on 2017/9/13. 6 | // Copyright © 2017年 HaRi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /JQImagePickerDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // JQImagePickerDemo 4 | // 5 | // Created by 韩俊强 on 2017/9/13. 6 | // Copyright © 2017年 HaRi. All rights reserved. 7 | // 手机加iOS开发者交流群:①群:446310206 ②群:426087546 8 | // 9 | 10 | #import "ViewController.h" 11 | #import "UIImage+GCAdd.h" 12 | #import "JQImagePicker.h" 13 | 14 | double scale = 9.0/16.0; // 经典16:9裁剪 15 | 16 | @interface ViewController () 17 | 18 | @property (nonatomic, assign) BOOL customCut; 19 | @property (weak, nonatomic) IBOutlet UIImageView *currentImageView; 20 | @property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstrint; 21 | @property (weak, nonatomic) IBOutlet NSLayoutConstraint *widthConstrint; 22 | 23 | @end 24 | 25 | @implementation ViewController 26 | 27 | - (void)viewDidLoad { 28 | [super viewDidLoad]; 29 | // Do any additional setup after loading the view, typically from a nib. 30 | } 31 | 32 | // 系统裁剪 33 | - (IBAction)systemCutAction:(id)sender 34 | { 35 | _customCut = NO; 36 | [self createAlertViewController:NO]; 37 | } 38 | 39 | // 自定义裁剪 40 | - (IBAction)customCutAction:(id)sender 41 | { 42 | _customCut = YES; 43 | [self createAlertViewController:YES]; 44 | } 45 | 46 | // 选择照片方式 47 | - (void)createAlertViewController:(BOOL)cut 48 | { 49 | UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"请选择图片" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; 50 | UIAlertAction *photoAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){ 51 | if (cut) { // 自定义裁剪 52 | JQImagePicker *imagePicker = [JQImagePicker sharedInstance]; 53 | imagePicker.delegate = self; 54 | [imagePicker showImagePickerWithType:ImagePickerCamera InViewController:self Scale:scale]; 55 | } else {// 普通裁剪 56 | JQImagePicker *imagePicker = [JQImagePicker sharedInstance]; 57 | imagePicker.delegate = self; 58 | [imagePicker showOriginalImagePickerWithType:ImagePickerCamera InViewController:self]; 59 | } 60 | }]; 61 | UIAlertAction *libraryAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 62 | 63 | if (cut) { 64 | JQImagePicker *imagePicker = [JQImagePicker sharedInstance]; 65 | imagePicker.delegate = self; 66 | [imagePicker showImagePickerWithType:ImagePickerPhoto InViewController:self Scale:scale]; 67 | } else { 68 | JQImagePicker *imagePicker = [JQImagePicker sharedInstance]; 69 | imagePicker.delegate = self; 70 | [imagePicker showOriginalImagePickerWithType:ImagePickerPhoto InViewController:self]; 71 | } 72 | 73 | }]; 74 | UIAlertAction *closeAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; 75 | [alertVC addAction:closeAction]; 76 | [alertVC addAction:libraryAction]; 77 | [alertVC addAction:photoAction]; 78 | [self presentViewController:alertVC animated:YES completion:nil]; 79 | } 80 | 81 | #pragma mark - JQImagePicker Delegate 82 | 83 | - (void)imagePickerDidCancel:(JQImagePicker *)imagePicker 84 | { 85 | NSLog(@"取消"); 86 | } 87 | 88 | - (void)imagePicker:(JQImagePicker *)imagePicker didFinished:(UIImage *)editedImage 89 | { 90 | NSLog(@"%@",editedImage); 91 | if (_customCut) { 92 | UIImage * customImage = [editedImage imageByResizeToSize:CGSizeMake(400*(16.0/9),400)]; 93 | self.widthConstrint.constant = 400*scale; 94 | self.heightConstrint.constant = 200*scale; 95 | self.currentImageView.image = customImage; 96 | } else { 97 | self.widthConstrint.constant = 200; 98 | self.heightConstrint.constant = 200; 99 | self.currentImageView.image = editedImage; 100 | } 101 | } 102 | 103 | 104 | - (void)didReceiveMemoryWarning { 105 | [super didReceiveMemoryWarning]; 106 | // Dispose of any resources that can be recreated. 107 | } 108 | 109 | 110 | @end 111 | -------------------------------------------------------------------------------- /JQImagePickerDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // JQImagePickerDemo 4 | // 5 | // Created by 韩俊强 on 2017/9/13. 6 | // Copyright © 2017年 HaRi. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /JQImagePickerDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /JQImagePickerDemoTests/JQImagePickerDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // JQImagePickerDemoTests.m 3 | // JQImagePickerDemoTests 4 | // 5 | // Created by 韩俊强 on 2017/9/13. 6 | // Copyright © 2017年 HaRi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JQImagePickerDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation JQImagePickerDemoTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /JQImagePickerDemoUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /JQImagePickerDemoUITests/JQImagePickerDemoUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // JQImagePickerDemoUITests.m 3 | // JQImagePickerDemoUITests 4 | // 5 | // Created by 韩俊强 on 2017/9/13. 6 | // Copyright © 2017年 HaRi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JQImagePickerDemoUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation JQImagePickerDemoUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 HanJunqiang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JQImagePicker 2 | 前言 3 | === 4 | iOS照片自定义裁剪, 自定义宽高比裁剪, 经典16:9等裁剪方式,代码调用简单精炼. 5 | ##### 1.自定义裁剪 6 | 7 | ![自定义裁剪](https://github.com/xiaohange/JQImagePicker/blob/master/%E6%95%88%E6%9E%9C%E5%9B%BE1.gif?raw=true) 8 | 9 | ##### 2.系统自带裁剪 10 | ![系统自带裁剪](https://github.com/xiaohange/JQImagePicker/blob/master/%E6%95%88%E6%9E%9C%E5%9B%BE2.gif?raw=true) 11 | 12 | ## 更新记录 13 | -1.0.1 14 | 15 | 2019.04.09 fix: 修复已知 bug; 16 | 17 | - 0.0.1 18 | 19 | 发布第一版本 0.0.1 20 | 21 | ## Installation 22 | 23 | - 1.Drag all source files under floder `JQImagePicker ` to your project. 24 | 25 | - 2.pod: `JQImagePicker ` 26 | 27 | ## Usage 28 | 29 | ``` 30 | #import "JQImagePicker.h" 31 | ``` 32 | ##### 1.系统自带裁剪 33 | 34 | ``` 35 | // 拍照 36 | JQImagePicker *imagePicker = [JQImagePicker sharedInstance]; 37 | imagePicker.delegate = self; 38 | [imagePicker showOriginalImagePickerWithType:ImagePickerCamera InViewController:self]; 39 | ``` 40 | 41 | ``` 42 | // 相册 43 | JQImagePicker *imagePicker = [JQImagePicker sharedInstance]; 44 | imagePicker.delegate = self; 45 | [imagePicker showOriginalImagePickerWithType:ImagePickerPhoto InViewController:self]; 46 | ``` 47 | ##### 2.自定义裁剪 48 | ``` 49 | // 拍照 50 | JQImagePicker *imagePicker = [JQImagePicker sharedInstance]; 51 | imagePicker.delegate = self; 52 | [imagePicker showImagePickerWithType:ImagePickerCamera InViewController:self Scale:scale]; 53 | ``` 54 | ``` 55 | // 相册 56 | JQImagePicker *imagePicker = [JQImagePicker sharedInstance]; 57 | imagePicker.delegate = self; 58 | [imagePicker showImagePickerWithType:ImagePickerPhoto InViewController:self Scale:scale]; 59 | ``` 60 | 61 | ##### 3.JQImagePickerDelegate 62 | ``` 63 | - (void)imagePickerDidCancel:(JQImagePicker *)imagePicker 64 | { 65 | NSLog(@"取消"); 66 | } 67 | 68 | - (void)imagePicker:(JQImagePicker *)imagePicker didFinished:(UIImage *)editedImage 69 | { 70 | NSLog(@"裁剪后:%@",editedImage); 71 | } 72 | ``` 73 | ## Star 74 | 75 | [CSDN博客](http://blog.csdn.net/qq_31810357) 76 | 77 | 手机加iOS开发者交流群:①群:446310206 ②群:426087546 喜欢就❤️❤️❤️star一下吧! 78 | 79 | Love is every every every star! Your support is my renewed motivation! 80 | 81 | ## License 82 | 83 | This code is distributed under the terms and conditions of the [MIT license](LICENSE). 84 | -------------------------------------------------------------------------------- /效果图1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaohange/JQImagePicker/1a69acb419a29bb3391f870f74261559bd9d6b6b/效果图1.gif -------------------------------------------------------------------------------- /效果图2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaohange/JQImagePicker/1a69acb419a29bb3391f870f74261559bd9d6b6b/效果图2.gif --------------------------------------------------------------------------------