From 00666bbac48db357e5f3bd7662ec8ca6dda8e15a Mon Sep 17 00:00:00 2001 From: Vitalii Parovishnyk Date: Tue, 25 Apr 2017 11:11:10 +0300 Subject: [PATCH] Updated project for Swift 3.1 --- Example/ExampleCropViewController.swift | 21 ++++++----- ...t => UIColor+IGRPhonoTweakExtension.swift} | 2 +- .../CropView/IGRCropCornerLine.swift | 6 +-- .../CropView/IGRCropCornerView.swift | 4 -- IGRPhotoTweaks/CropView/IGRCropGridLine.swift | 6 +-- IGRPhotoTweaks/CropView/IGRCropLine.swift | 6 +-- IGRPhotoTweaks/CropView/IGRCropMaskView.swift | 6 +-- IGRPhotoTweaks/CropView/IGRCropView.swift | 6 +-- .../CropView/IGRPhotoContentView.swift | 4 -- IGRPhotoTweaks/IGRPhotoTweakView.swift | 4 -- .../IGRPhotoTweakViewController.swift | 37 +++++++++++++------ IGRPhotoTweaks/IGRRadianAngle.swift | 4 +- 12 files changed, 46 insertions(+), 60 deletions(-) rename IGRPhotoTweaks/Category/{UIColor+Tweak.swift => UIColor+IGRPhonoTweakExtension.swift} (93%) diff --git a/Example/ExampleCropViewController.swift b/Example/ExampleCropViewController.swift index 4e2e679..44a88a0 100644 --- a/Example/ExampleCropViewController.swift +++ b/Example/ExampleCropViewController.swift @@ -29,15 +29,6 @@ class ExampleCropViewController: IGRPhotoTweakViewController { override func viewDidLoad() { super.viewDidLoad() - //FIXME: Themes Preview -// IGRCropLine.appearance().backgroundColor = UIColor.green -// IGRCropGridLine.appearance().backgroundColor = UIColor.yellow -// IGRCropCornerView.appearance().backgroundColor = UIColor.purple -// IGRCropCornerLine.appearance().backgroundColor = UIColor.orange -// IGRCropMaskView.appearance().backgroundColor = UIColor.blue -// IGRPhotoContentView.appearance().backgroundColor = UIColor.gray -// IGRPhotoTweakView.appearance().backgroundColor = UIColor.brown - self.setupSlider() } @@ -46,6 +37,18 @@ class ExampleCropViewController: IGRPhotoTweakViewController { // Dispose of any resources that can be recreated. } + //FIXME: Themes Preview + /*override open func setupThemes() { + + IGRCropLine.appearance().backgroundColor = UIColor.green + IGRCropGridLine.appearance().backgroundColor = UIColor.yellow + IGRCropCornerView.appearance().backgroundColor = UIColor.purple + IGRCropCornerLine.appearance().backgroundColor = UIColor.orange + IGRCropMaskView.appearance().backgroundColor = UIColor.blue + IGRPhotoContentView.appearance().backgroundColor = UIColor.gray + IGRPhotoTweakView.appearance().backgroundColor = UIColor.brown + }*/ + fileprivate func setupSlider() { self.angelSlider?.minimumValue = -Float(IGRRadianAngle.toRadians(45)) self.angelSlider?.maximumValue = Float(IGRRadianAngle.toRadians(45)) diff --git a/IGRPhotoTweaks/Category/UIColor+Tweak.swift b/IGRPhotoTweaks/Category/UIColor+IGRPhonoTweakExtension.swift similarity index 93% rename from IGRPhotoTweaks/Category/UIColor+Tweak.swift rename to IGRPhotoTweaks/Category/UIColor+IGRPhonoTweakExtension.swift index 263252e..b90bf07 100644 --- a/IGRPhotoTweaks/Category/UIColor+Tweak.swift +++ b/IGRPhotoTweaks/Category/UIColor+IGRPhonoTweakExtension.swift @@ -1,5 +1,5 @@ // -// UIColor+Tweak.swift +// UIColor+IGRPhonoTweakExtension.swift // IGRPhotoTweaks // // Created by Vitalii Parovishnyk on 2/6/17. diff --git a/IGRPhotoTweaks/CropView/IGRCropCornerLine.swift b/IGRPhotoTweaks/CropView/IGRCropCornerLine.swift index a194c42..de01016 100644 --- a/IGRPhotoTweaks/CropView/IGRCropCornerLine.swift +++ b/IGRPhotoTweaks/CropView/IGRCropCornerLine.swift @@ -9,9 +9,5 @@ import UIKit @objc public class IGRCropCornerLine: UIView { - - override public class func initialize () { - self.appearance().backgroundColor = UIColor.cropLine() - } - + } diff --git a/IGRPhotoTweaks/CropView/IGRCropCornerView.swift b/IGRPhotoTweaks/CropView/IGRCropCornerView.swift index 06466db..e73ba95 100644 --- a/IGRPhotoTweaks/CropView/IGRCropCornerView.swift +++ b/IGRPhotoTweaks/CropView/IGRCropCornerView.swift @@ -9,10 +9,6 @@ import UIKit @objc public class IGRCropCornerView: UIView { - - override public class func initialize () { - self.appearance().backgroundColor = UIColor.clear - } init(cornerType type: CropCornerType, lineWidth: CGFloat, lineLenght: CGFloat) { super.init(frame: CGRect(x: 0.0, y: 0.0, width: lineLenght, height: lineLenght)) diff --git a/IGRPhotoTweaks/CropView/IGRCropGridLine.swift b/IGRPhotoTweaks/CropView/IGRCropGridLine.swift index 4f6e563..405b461 100644 --- a/IGRPhotoTweaks/CropView/IGRCropGridLine.swift +++ b/IGRPhotoTweaks/CropView/IGRCropGridLine.swift @@ -9,9 +9,5 @@ import UIKit @objc public class IGRCropGridLine: UIView { - - override public class func initialize () { - self.appearance().backgroundColor = UIColor.gridLine() - } - + } diff --git a/IGRPhotoTweaks/CropView/IGRCropLine.swift b/IGRPhotoTweaks/CropView/IGRCropLine.swift index 6de8c0c..a0a77f9 100644 --- a/IGRPhotoTweaks/CropView/IGRCropLine.swift +++ b/IGRPhotoTweaks/CropView/IGRCropLine.swift @@ -9,9 +9,5 @@ import UIKit @objc public class IGRCropLine: UIView { - - override public class func initialize () { - self.appearance().backgroundColor = UIColor.cropLine() - } - + } diff --git a/IGRPhotoTweaks/CropView/IGRCropMaskView.swift b/IGRPhotoTweaks/CropView/IGRCropMaskView.swift index 1ef8d19..a572c5e 100644 --- a/IGRPhotoTweaks/CropView/IGRCropMaskView.swift +++ b/IGRPhotoTweaks/CropView/IGRCropMaskView.swift @@ -9,9 +9,5 @@ import UIKit @objc public class IGRCropMaskView: UIView { - - override public class func initialize () { - self.appearance().backgroundColor = UIColor.mask() - } - + } diff --git a/IGRPhotoTweaks/CropView/IGRCropView.swift b/IGRPhotoTweaks/CropView/IGRCropView.swift index 12e3643..3558f86 100644 --- a/IGRPhotoTweaks/CropView/IGRCropView.swift +++ b/IGRPhotoTweaks/CropView/IGRCropView.swift @@ -56,11 +56,7 @@ class IGRCropView: UIView { // MARK: - Life Cicle - override class func initialize () { - self.appearance().backgroundColor = UIColor.clear - } - - init(frame: CGRect, cornerBorderWidth: CGFloat, cornerBorderLength:CGFloat) { + init(frame: CGRect, cornerBorderWidth: CGFloat, cornerBorderLength: CGFloat) { super.init(frame: frame) self.cornerBorderLength = cornerBorderLength diff --git a/IGRPhotoTweaks/CropView/IGRPhotoContentView.swift b/IGRPhotoTweaks/CropView/IGRPhotoContentView.swift index aa8b988..bf3e670 100644 --- a/IGRPhotoTweaks/CropView/IGRPhotoContentView.swift +++ b/IGRPhotoTweaks/CropView/IGRPhotoContentView.swift @@ -10,10 +10,6 @@ import UIKit @objc public class IGRPhotoContentView: UIView { - override public class func initialize () { - self.appearance().backgroundColor = UIColor.clear - } - var imageView: UIImageView! var image: UIImage! { didSet { diff --git a/IGRPhotoTweaks/IGRPhotoTweakView.swift b/IGRPhotoTweaks/IGRPhotoTweakView.swift index b3386f6..e7a6758 100644 --- a/IGRPhotoTweaks/IGRPhotoTweakView.swift +++ b/IGRPhotoTweaks/IGRPhotoTweakView.swift @@ -82,10 +82,6 @@ import UIKit // MARK: - Life Cicle - override public class func initialize () { - self.appearance().backgroundColor = UIColor.photoTweakCanvasBackground() - } - init(frame: CGRect, image: UIImage, customizationDelegate: IGRPhotoTweakViewCustomizationDelegate!) { super.init(frame: frame) diff --git a/IGRPhotoTweaks/IGRPhotoTweakViewController.swift b/IGRPhotoTweaks/IGRPhotoTweakViewController.swift index d5be268..8f5c99d 100644 --- a/IGRPhotoTweaks/IGRPhotoTweakViewController.swift +++ b/IGRPhotoTweaks/IGRPhotoTweakViewController.swift @@ -55,13 +55,14 @@ import Photos override open func viewDidLoad() { super.viewDidLoad() - + self.automaticallyAdjustsScrollViewInsets = false self.view.clipsToBounds = true + self.setupThemes() self.setupSubviews() } - + override open func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. @@ -76,6 +77,17 @@ import Photos self.view.sendSubview(toBack: self.photoView) } + open func setupThemes() { + IGRPhotoTweakView.appearance().backgroundColor = UIColor.photoTweakCanvasBackground() + IGRPhotoContentView.appearance().backgroundColor = UIColor.clear + IGRCropView.appearance().backgroundColor = UIColor.clear + IGRCropGridLine.appearance().backgroundColor = UIColor.gridLine() + IGRCropLine.appearance().backgroundColor = UIColor.cropLine() + IGRCropCornerView.appearance().backgroundColor = UIColor.clear + IGRCropCornerLine.appearance().backgroundColor = UIColor.cropLine() + IGRCropMaskView.appearance().backgroundColor = UIColor.mask() + } + // MARK: - Public open func changedAngel(value: CGFloat) { @@ -133,7 +145,9 @@ import Photos } else { DispatchQueue.main.async{ - let ac = UIAlertController(title: "Authorization error", message: "App don't granted to access to Photo Library", preferredStyle: .alert) + let ac = UIAlertController(title: "Authorization error", + message: "App don't granted to access to Photo Library", + preferredStyle: .alert) ac.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) ac.addAction(UIAlertAction(title: "Settings", style: .default, handler: { (action) in guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else { @@ -189,11 +203,11 @@ import Photos case .left, .leftMirrored: transform = transform.translatedBy(x: width, y: 0) - transform = transform.rotated(by: 0.5*CGFloat.pi) + transform = transform.rotated(by: 0.5 * CGFloat.pi) case .right, .rightMirrored: transform = transform.translatedBy(x: 0, y: height) - transform = transform.rotated(by: -0.5*CGFloat.pi) + transform = transform.rotated(by: -0.5 * CGFloat.pi) case .up, .upMirrored: break @@ -250,7 +264,7 @@ import Photos fileprivate func newTransformedImage(_ transform: CGAffineTransform, sourceImage: CGImage, sourceSize: CGSize, outputWidth: CGFloat, cropSize: CGSize, imageViewSize: CGSize) -> CGImage { - + let aspect: CGFloat = cropSize.height / cropSize.width let outputSize = CGSize(width: outputWidth, height: (outputWidth * aspect)) @@ -263,17 +277,18 @@ import Photos bitmapInfo: sourceImage.bitmapInfo.rawValue) context?.setFillColor(UIColor.clear.cgColor) context?.fill(CGRect(x: 0.0, y: 0.0, width: (outputSize.width), height: (outputSize.height))) - var uiCoords = CGAffineTransform(scaleX: outputSize.width / cropSize.width, y: outputSize.height / cropSize.height) + var uiCoords = CGAffineTransform(scaleX: outputSize.width / cropSize.width, + y: outputSize.height / cropSize.height) uiCoords = uiCoords.translatedBy(x: cropSize.width / 2.0, y: cropSize.height / 2.0) uiCoords = uiCoords.scaledBy(x: 1.0, y: -1.0) context?.concatenate(uiCoords) context?.concatenate(transform) context?.scaleBy(x: 1.0, y: -1.0) context?.draw(sourceImage, in: CGRect(x: (-imageViewSize.width / 2.0), - y: (-imageViewSize.height / 2.0), - width: imageViewSize.width, - height: imageViewSize.height)) - + y: (-imageViewSize.height / 2.0), + width: imageViewSize.width, + height: imageViewSize.height)) + let resultRef: CGImage = context!.makeImage()! return resultRef diff --git a/IGRPhotoTweaks/IGRRadianAngle.swift b/IGRPhotoTweaks/IGRRadianAngle.swift index d1dc80b..7f3e6ea 100644 --- a/IGRPhotoTweaks/IGRRadianAngle.swift +++ b/IGRPhotoTweaks/IGRRadianAngle.swift @@ -11,10 +11,10 @@ import CoreGraphics @objc open class IGRRadianAngle : NSObject { static open func toRadians(_ degrees: CGFloat) -> CGFloat { - return (degrees * CGFloat(M_PI) / 180.0) + return (degrees * CGFloat.pi / 180.0) } static open func toDegrees(_ radians: CGFloat) -> CGFloat { - return (radians * 180.0 / CGFloat(M_PI)) + return (radians * 180.0 / CGFloat.pi) } }