Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Updated project for Swift 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ikorich committed Apr 25, 2017
1 parent 27d4b72 commit 00666bb
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 60 deletions.
21 changes: 12 additions & 9 deletions Example/ExampleCropViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// UIColor+Tweak.swift
// UIColor+IGRPhonoTweakExtension.swift
// IGRPhotoTweaks
//
// Created by Vitalii Parovishnyk on 2/6/17.
Expand Down
6 changes: 1 addition & 5 deletions IGRPhotoTweaks/CropView/IGRCropCornerLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@
import UIKit

@objc public class IGRCropCornerLine: UIView {

override public class func initialize () {
self.appearance().backgroundColor = UIColor.cropLine()
}


}
4 changes: 0 additions & 4 deletions IGRPhotoTweaks/CropView/IGRCropCornerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 1 addition & 5 deletions IGRPhotoTweaks/CropView/IGRCropGridLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@
import UIKit

@objc public class IGRCropGridLine: UIView {

override public class func initialize () {
self.appearance().backgroundColor = UIColor.gridLine()
}


}
6 changes: 1 addition & 5 deletions IGRPhotoTweaks/CropView/IGRCropLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@
import UIKit

@objc public class IGRCropLine: UIView {

override public class func initialize () {
self.appearance().backgroundColor = UIColor.cropLine()
}


}
6 changes: 1 addition & 5 deletions IGRPhotoTweaks/CropView/IGRCropMaskView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@
import UIKit

@objc public class IGRCropMaskView: UIView {

override public class func initialize () {
self.appearance().backgroundColor = UIColor.mask()
}


}
6 changes: 1 addition & 5 deletions IGRPhotoTweaks/CropView/IGRCropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions IGRPhotoTweaks/CropView/IGRPhotoContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions IGRPhotoTweaks/IGRPhotoTweakView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
37 changes: 26 additions & 11 deletions IGRPhotoTweaks/IGRPhotoTweakViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions IGRPhotoTweaks/IGRRadianAngle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 00666bb

Please sign in to comment.