From 8207ae64ba01fde47cdfd7cb8066e3638c1d5787 Mon Sep 17 00:00:00 2001 From: janlionly Date: Wed, 24 Feb 2021 17:09:24 +0800 Subject: [PATCH 1/6] feat: change crop view toolbar position and support SPM --- GKClasses/GKImageCropViewController.m | 13 +++++++-- Package.swift | 29 +++++++++++++++++++ Sources/GKImagePicker/GKImagePicker.swift | 3 ++ .../GKImagePickerTests.swift | 15 ++++++++++ .../GKImagePickerTests/XCTestManifests.swift | 9 ++++++ Tests/LinuxMain.swift | 7 +++++ 6 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 Package.swift create mode 100644 Sources/GKImagePicker/GKImagePicker.swift create mode 100644 Tests/GKImagePickerTests/GKImagePickerTests.swift create mode 100644 Tests/GKImagePickerTests/XCTestManifests.swift create mode 100644 Tests/LinuxMain.swift diff --git a/GKClasses/GKImageCropViewController.m b/GKClasses/GKImageCropViewController.m index f88bdf5..de9ec4d 100644 --- a/GKClasses/GKImageCropViewController.m +++ b/GKClasses/GKImageCropViewController.m @@ -38,7 +38,11 @@ @implementation GKImageCropViewController - (void)_actionCancel{ - [self.navigationController popViewControllerAnimated:YES]; + if (self.navigationController && self.navigationController.viewControllers.count > 1) { + [self.navigationController popViewControllerAnimated:YES]; + } else { + [self dismissViewControllerAnimated:YES completion:NULL]; + } } @@ -224,7 +228,12 @@ - (void)viewWillLayoutSubviews{ [super viewWillLayoutSubviews]; self.imageCropView.frame = self.view.bounds; - self.toolbar.frame = CGRectMake(0, CGRectGetHeight(self.view.frame) - 54, 320, 54); + CGSize size = [[UIScreen mainScreen] bounds].size; + UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0); + if (@available(iOS 11.0, *)) { + insets = [UIApplication sharedApplication].keyWindow.safeAreaInsets; + } + self.toolbar.frame = CGRectMake(0, size.height - 54 - insets.bottom, size.width, 54); } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..8bad7c1 --- /dev/null +++ b/Package.swift @@ -0,0 +1,29 @@ +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "GKImagePicker", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "GKImagePicker", + targets: ["GKImagePicker"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "GKImagePicker", + dependencies: [], + path: "GKClasses"), + .testTarget( + name: "GKImagePickerTests", + dependencies: ["GKImagePicker"]), + ] +) diff --git a/Sources/GKImagePicker/GKImagePicker.swift b/Sources/GKImagePicker/GKImagePicker.swift new file mode 100644 index 0000000..166a759 --- /dev/null +++ b/Sources/GKImagePicker/GKImagePicker.swift @@ -0,0 +1,3 @@ +struct GKImagePicker { + var text = "Hello, World!" +} diff --git a/Tests/GKImagePickerTests/GKImagePickerTests.swift b/Tests/GKImagePickerTests/GKImagePickerTests.swift new file mode 100644 index 0000000..88bbbd5 --- /dev/null +++ b/Tests/GKImagePickerTests/GKImagePickerTests.swift @@ -0,0 +1,15 @@ +import XCTest +@testable import GKImagePicker + +final class GKImagePickerTests: XCTestCase { + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct + // results. + XCTAssertEqual(GKImagePicker().text, "Hello, World!") + } + + static var allTests = [ + ("testExample", testExample), + ] +} diff --git a/Tests/GKImagePickerTests/XCTestManifests.swift b/Tests/GKImagePickerTests/XCTestManifests.swift new file mode 100644 index 0000000..885d0c3 --- /dev/null +++ b/Tests/GKImagePickerTests/XCTestManifests.swift @@ -0,0 +1,9 @@ +import XCTest + +#if !canImport(ObjectiveC) +public func allTests() -> [XCTestCaseEntry] { + return [ + testCase(GKImagePickerTests.allTests), + ] +} +#endif diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..efa2ad1 --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,7 @@ +import XCTest + +import GKImagePickerTests + +var tests = [XCTestCaseEntry]() +tests += GKImagePickerTests.allTests() +XCTMain(tests) From 2d340fca38f51a5cc077a41ea2a7f65abecd348f Mon Sep 17 00:00:00 2001 From: janlionly Date: Wed, 24 Feb 2021 17:17:04 +0800 Subject: [PATCH 2/6] change crop view toolbar position and support SPM --- GKClasses/GKImagePicker.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/GKClasses/GKImagePicker.h b/GKClasses/GKImagePicker.h index a8fa789..0a7d38b 100644 --- a/GKClasses/GKImagePicker.h +++ b/GKClasses/GKImagePicker.h @@ -7,6 +7,8 @@ // #import +#import +#import @protocol GKImagePickerDelegate; @@ -38,4 +40,4 @@ */ - (void)imagePickerDidCancel:(GKImagePicker *)imagePicker; -@end \ No newline at end of file +@end From d794245b7132dfa723e3d0bf02c4475ad5531594 Mon Sep 17 00:00:00 2001 From: janlionly Date: Wed, 24 Feb 2021 17:43:43 +0800 Subject: [PATCH 3/6] fix: add include header --- GKClasses/include/GKImageCropViewController.h | 28 ++++++++++++ GKClasses/include/GKImagePicker.h | 43 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 GKClasses/include/GKImageCropViewController.h create mode 100644 GKClasses/include/GKImagePicker.h diff --git a/GKClasses/include/GKImageCropViewController.h b/GKClasses/include/GKImageCropViewController.h new file mode 100644 index 0000000..1eb33e7 --- /dev/null +++ b/GKClasses/include/GKImageCropViewController.h @@ -0,0 +1,28 @@ +// +// GKImageCropViewController.h +// GKImagePicker +// +// Created by Georg Kitz on 6/1/12. +// Copyright (c) 2012 Aurora Apps. All rights reserved. +// + +#import + +@protocol GKImageCropControllerDelegate; + +@interface GKImageCropViewController : UIViewController{ + UIImage *_croppedImage; +} + +@property (nonatomic, strong) UIImage *sourceImage; +@property (nonatomic, assign) CGSize cropSize; //size of the crop rect, default is 320x320 +@property (nonatomic, assign) BOOL resizeableCropArea; +@property (nonatomic, strong) id delegate; + +@end + + +@protocol GKImageCropControllerDelegate +@required +- (void)imageCropController:(GKImageCropViewController *)imageCropController didFinishWithCroppedImage:(UIImage *)croppedImage; +@end \ No newline at end of file diff --git a/GKClasses/include/GKImagePicker.h b/GKClasses/include/GKImagePicker.h new file mode 100644 index 0000000..0a7d38b --- /dev/null +++ b/GKClasses/include/GKImagePicker.h @@ -0,0 +1,43 @@ +// +// GKImagePicker.h +// GKImagePicker +// +// Created by Georg Kitz on 6/1/12. +// Copyright (c) 2012 Aurora Apps. All rights reserved. +// + +#import +#import +#import + +@protocol GKImagePickerDelegate; + +@interface GKImagePicker : NSObject + +@property (nonatomic, weak) id delegate; +@property (nonatomic, assign) CGSize cropSize; //default value is 320x320 (which is exactly the same as the normal imagepicker uses) +@property (nonatomic, strong, readonly) UIImagePickerController *imagePickerController; +@property (nonatomic, assign) BOOL resizeableCropArea; + +@end + + +@protocol GKImagePickerDelegate + +@optional + +/** + * @method imagePicker:pickedImage: gets called when a user has chosen an image + * @param imagePicker, the image picker instance + * @param image, the picked and cropped image + */ +- (void)imagePicker:(GKImagePicker *)imagePicker pickedImage:(UIImage *)image; + + +/** + * @method imagePickerDidCancel: gets called when the user taps the cancel button + * @param imagePicker, the image picker instance + */ +- (void)imagePickerDidCancel:(GKImagePicker *)imagePicker; + +@end From fb019157e05e2408fd91ca819ef7a3e37baaf170 Mon Sep 17 00:00:00 2001 From: janlionly Date: Wed, 24 Feb 2021 17:45:35 +0800 Subject: [PATCH 4/6] delete unuse source --- Sources/GKImagePicker/GKImagePicker.swift | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 Sources/GKImagePicker/GKImagePicker.swift diff --git a/Sources/GKImagePicker/GKImagePicker.swift b/Sources/GKImagePicker/GKImagePicker.swift deleted file mode 100644 index 166a759..0000000 --- a/Sources/GKImagePicker/GKImagePicker.swift +++ /dev/null @@ -1,3 +0,0 @@ -struct GKImagePicker { - var text = "Hello, World!" -} From 61971b85494f8f943e60028d47402a4292257ca0 Mon Sep 17 00:00:00 2001 From: janlionly Date: Sat, 31 Jul 2021 20:57:42 +0800 Subject: [PATCH 5/6] docs: support for cocoapods --- GKImagePicker.podspec | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 GKImagePicker.podspec diff --git a/GKImagePicker.podspec b/GKImagePicker.podspec new file mode 100644 index 0000000..e7e7df4 --- /dev/null +++ b/GKImagePicker.podspec @@ -0,0 +1,16 @@ +Pod::Spec.new do |s| + s.name = 'GKImagePicker' + s.version = '1.0.0' + s.summary = 'Image Picker easy for usage. Compatible with both Swift and Objective-C.' + + s.homepage = 'https://github.com/janlionly/GKImagePicker' + s.license = { :type => 'MIT', :file => 'LICENSE' } + s.author = { 'janlionly' => 'janlionly@gmail.com' } + s.source = { :git => 'https://github.com/janlionly/GKImagePicker.git', :tag => s.version.to_s } + s.social_media_url = 'https://twitter.com/janlionly' + s.ios.deployment_target = '9.0' + s.requires_arc = true + s.source_files = 'Sources/GKClasses/*.{h,m}' + s.swift_versions = ['4.2', '5.0', '5.1', '5.2', '5.3'] + s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.2' } +end From e6fbd42dfdef6bdf3c920092d2bf69be3a91c218 Mon Sep 17 00:00:00 2001 From: janlionly Date: Sat, 31 Jul 2021 21:56:48 +0800 Subject: [PATCH 6/6] docs: change info --- GKImagePicker.podspec | 2 +- license | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/GKImagePicker.podspec b/GKImagePicker.podspec index e7e7df4..4294648 100644 --- a/GKImagePicker.podspec +++ b/GKImagePicker.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.social_media_url = 'https://twitter.com/janlionly' s.ios.deployment_target = '9.0' s.requires_arc = true - s.source_files = 'Sources/GKClasses/*.{h,m}' + s.source_files = 'GKClasses/*.{h,m}' s.swift_versions = ['4.2', '5.0', '5.1', '5.2', '5.3'] s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.2' } end diff --git a/license b/license index b51f329..b79f9c3 100644 --- a/license +++ b/license @@ -1,11 +1,13 @@ -Copyright (C) 2012, Georg Kitz, @gekitz +MIT License -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: +Copyright (c) 2020 janlionly + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. @@ -16,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE.