Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade for Swift 5.0 #38

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AKImageCropperView.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "AKImageCropperView"
s.version = "2.0.0"
s.version = "2.0.1"
s.homepage = "https://github.com/artemkrachulov/AKImageCropperView"
s.summary = "Responsive image cropper"
s.description = <<-DESC
Expand All @@ -21,5 +21,5 @@ Pod::Spec.new do |s|
}

s.source_files = "AKImageCropperView/*.{swift}"
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.0' }
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5.0' }
end
2 changes: 1 addition & 1 deletion AKImageCropperView/AKImageCropperOverlayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ open class AKImageCropperOverlayView: UIView {
return
}

let animations: () -> Void = { _ in
let animations: () -> Void = {
self.gridView.alpha = show ? 1 : 0
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public struct AKImageCropperCropViewConfiguration {
- duration: The duration of the transition animation, measured in seconds.
- options: Specifies the supported animation curves.
*/
public var animation: (duration: TimeInterval, options: UIViewAnimationOptions) = (duration: 0.3, options: .curveEaseInOut)
public var animation: (duration: TimeInterval, options: UIView.AnimationOptions) = (duration: 0.3, options: .curveEaseInOut)

/// Edges insets for crop rectangle. Static values for programmatically rotation.

public var cropRectInsets = UIEdgeInsetsMake(20, 20, 20, 20)
public var cropRectInsets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)

/// The smallest value for the crop rectangle sizes. Initial value of this property is 60 pixels width and 60 pixels height.
public var minCropRectSize: CGSize = CGSize(width: 60, height: 60)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public struct AKImageCropperCropViewConfigurationOverlay {
public var isBlurEnabled: Bool = true

/// The intensity of the blur effect.
public var blurStyle: UIBlurEffectStyle = .dark
public var blurStyle: UIBlurEffect.Style = .dark

/// The blur effect alpha value.
public var blurAlpha: CGFloat = 0.6
Expand Down
6 changes: 3 additions & 3 deletions AKImageCropperView/AKImageCropperScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class AKImageCropperScrollView: UIScrollView {

/** Return visible rect of an UIScrollView's content */

open var visibleRect: CGRect {
public var visibleRect: CGRect {
return CGRect(
x : contentInset.left,
y : contentInset.top,
Expand All @@ -25,7 +25,7 @@ final class AKImageCropperScrollView: UIScrollView {

/** Returns scaled visible rect of an UIScrollView's content */

open var scaledVisibleRect: CGRect {
public var scaledVisibleRect: CGRect {
return CGRect(
x : (contentOffset.x + contentInset.left) / zoomScale,
y : (contentOffset.y + contentInset.top) / zoomScale,
Expand All @@ -41,7 +41,7 @@ final class AKImageCropperScrollView: UIScrollView {
return view
}()

open var image: UIImage! {
public var image: UIImage! {
didSet {

/* Prepare scroll view to changing the image */
Expand Down
78 changes: 39 additions & 39 deletions AKImageCropperView/AKImageCropperView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ open class AKImageCropperView: UIView, UIScrollViewDelegate, UIGestureRecognizer
fileprivate var reversedRect: CGRect {
return CGRect(
origin : .zero,
size : ((angle / M_PI_2).truncatingRemainder(dividingBy: 2)) == 1
size : ((angle / Double.pi / 2).truncatingRemainder(dividingBy: 2)) == 1
? CGSize(width: frame.size.height, height: frame.size.width)
: frame.size)
}
Expand All @@ -52,24 +52,24 @@ open class AKImageCropperView: UIView, UIScrollViewDelegate, UIGestureRecognizer
var newEdgeInsets: UIEdgeInsets

switch angle {
case M_PI_2:
newEdgeInsets = UIEdgeInsetsMake(
minEdgeInsets.right,
minEdgeInsets.top,
minEdgeInsets.left,
minEdgeInsets.bottom)
case M_PI:
newEdgeInsets = UIEdgeInsetsMake(
minEdgeInsets.bottom,
minEdgeInsets.right,
minEdgeInsets.top,
minEdgeInsets.left)
case M_PI_2 * 3:
newEdgeInsets = UIEdgeInsetsMake(
minEdgeInsets.left,
minEdgeInsets.bottom,
minEdgeInsets.right,
minEdgeInsets.top)
case Double.pi / 2:
newEdgeInsets = UIEdgeInsets(
top: minEdgeInsets.right,
left: minEdgeInsets.top,
bottom: minEdgeInsets.left,
right: minEdgeInsets.bottom)
case Double.pi:
newEdgeInsets = UIEdgeInsets(
top: minEdgeInsets.bottom,
left: minEdgeInsets.right,
bottom: minEdgeInsets.top,
right: minEdgeInsets.left)
case Double.pi / 2 * 3:
newEdgeInsets = UIEdgeInsets(
top: minEdgeInsets.left,
left: minEdgeInsets.bottom,
bottom: minEdgeInsets.right,
right: minEdgeInsets.top)
default:
newEdgeInsets = minEdgeInsets
}
Expand All @@ -80,7 +80,7 @@ open class AKImageCropperView: UIView, UIScrollViewDelegate, UIGestureRecognizer
/** Reversed frame + edgeInsets direct to current rotation angle */

var reversedFrameWithInsets: CGRect {
return UIEdgeInsetsInsetRect(reversedRect, reversedEdgeInsets)
return reversedRect.inset(by: reversedEdgeInsets)
}

// MARK: -
Expand Down Expand Up @@ -427,7 +427,7 @@ open class AKImageCropperView: UIView, UIScrollViewDelegate, UIGestureRecognizer
- Parameter completion: A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL.
*/

open func showOverlayView(animationDuration duration: TimeInterval = 0, options: UIViewAnimationOptions = .curveEaseInOut, completion: ((Bool) -> Void)? = nil) {
open func showOverlayView(animationDuration duration: TimeInterval = 0, options: UIView.AnimationOptions = .curveEaseInOut, completion: ((Bool) -> Void)? = nil) {

guard let image = image, let overlayView = overlayView, !isOverlayViewActive && !isAnimation else {
return
Expand All @@ -437,7 +437,7 @@ open class AKImageCropperView: UIView, UIScrollViewDelegate, UIGestureRecognizer
savedProperty.save(scrollView: scrollView)
cancelZoomingTimer()

let _animations: () -> Void = { _ in
let _animations: () -> Void = {

self.layoutSubviews()

Expand Down Expand Up @@ -492,7 +492,7 @@ open class AKImageCropperView: UIView, UIScrollViewDelegate, UIGestureRecognizer
- Parameter completion: A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL.
*/

open func hideOverlayView(animationDuration duration: TimeInterval = 0, options: UIViewAnimationOptions = .curveEaseInOut, completion: ((Bool) -> Void)? = nil) {
open func hideOverlayView(animationDuration duration: TimeInterval = 0, options: UIView.AnimationOptions = .curveEaseInOut, completion: ((Bool) -> Void)? = nil) {

guard let image = image, let overlayView = overlayView, isOverlayViewActive && !isAnimation else {
return
Expand All @@ -504,7 +504,7 @@ open class AKImageCropperView: UIView, UIScrollViewDelegate, UIGestureRecognizer

isAnimation = true

let _animations: () -> Void = { _ in
let _animations: () -> Void = {

self.layoutSubviews()

Expand Down Expand Up @@ -561,16 +561,16 @@ open class AKImageCropperView: UIView, UIScrollViewDelegate, UIGestureRecognizer
- Parameter completion: A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL.
*/

open func rotate(_ angle: Double, withDuration duration: TimeInterval = 0, options: UIViewAnimationOptions = .curveEaseInOut, completion: ((Bool) -> Void)? = nil) {
open func rotate(_ angle: Double, withDuration duration: TimeInterval = 0, options: UIView.AnimationOptions = .curveEaseInOut, completion: ((Bool) -> Void)? = nil) {

guard angle.truncatingRemainder(dividingBy: M_PI_2) == 0 else {
guard angle.truncatingRemainder(dividingBy: Double.pi / 2) == 0 else {
return
}

self.angle = angle
savedProperty.save(scrollView: scrollView)

let _animations: () -> Void = { _ in
let _animations: () -> Void = {

self.rotateView.transform = CGAffineTransform(rotationAngle: CGFloat(angle))
self.layoutSubviews()
Expand Down Expand Up @@ -600,7 +600,7 @@ open class AKImageCropperView: UIView, UIScrollViewDelegate, UIGestureRecognizer
- Parameter completion: A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL.
*/

open func reset(animationDuration duration: TimeInterval = 0, options: UIViewAnimationOptions = .curveEaseInOut, completion: ((Bool) -> Void)? = nil) {
open func reset(animationDuration duration: TimeInterval = 0, options: UIView.AnimationOptions = .curveEaseInOut, completion: ((Bool) -> Void)? = nil) {

guard !isAnimation else {
return
Expand All @@ -610,7 +610,7 @@ open class AKImageCropperView: UIView, UIScrollViewDelegate, UIGestureRecognizer
angle = 0
cancelZoomingTimer()

let _animations: () -> Void = { _ in
let _animations: () -> Void = {

self.rotateView.transform = CGAffineTransform.identity

Expand Down Expand Up @@ -705,11 +705,11 @@ open class AKImageCropperView: UIView, UIScrollViewDelegate, UIGestureRecognizer

// Fix insets direct to orientation

return UIEdgeInsetsMake(
center.y + minEdgeInsets.top,
center.x + minEdgeInsets.left,
center.y + minEdgeInsets.bottom,
center.x + minEdgeInsets.right)
return UIEdgeInsets(
top: center.y + minEdgeInsets.top,
left: center.x + minEdgeInsets.left,
bottom: center.y + minEdgeInsets.bottom,
right: center.x + minEdgeInsets.right)
}

private func contentOffset(from savedContentOffsetPercentage: CGPointPercentage) -> CGPoint {
Expand All @@ -732,11 +732,11 @@ open class AKImageCropperView: UIView, UIScrollViewDelegate, UIGestureRecognizer

func cropperOverlayViewDidChangeCropRect(_ view: AKImageCropperOverlayView, _ cropRect: CGRect) {

scrollView.contentInset = UIEdgeInsetsMake(
cropRect.origin.y,
cropRect.origin.x,
view.frame.size.height - cropRect.size.height - cropRect.origin.y,
view.frame.size.width - cropRect.size.width - cropRect.origin.x)
scrollView.contentInset = UIEdgeInsets(
top: cropRect.origin.y,
left: cropRect.origin.x,
bottom: view.frame.size.height - cropRect.size.height - cropRect.origin.y,
right: view.frame.size.width - cropRect.size.width - cropRect.origin.x)

if cropRect.size.height > scrollView.contentSize.height || cropRect.size.width > scrollView.contentSize.width {

Expand Down
2 changes: 1 addition & 1 deletion AKImageCropperView/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.0.0</string>
<string>2.0.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[carthage-url]: https://github.com/Carthage/Carthage
[platform-bage]: https://img.shields.io/cocoapods/p/LFAlertController.svg
[platform-url]: http://cocoapods.org/pods/LFAlertController
[swift-bage]:https://img.shields.io/badge/swift-3.0-orange.svg
[swift-bage]:https://img.shields.io/badge/swift-5.0-orange.svg
[swift-url]: https://swift.org/
[license-bage]: https://img.shields.io/badge/License-MIT-blue.svg
[license-url]: LICENSE
Expand Down