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

Commit

Permalink
Fixed customization
Browse files Browse the repository at this point in the history
  • Loading branch information
ikorich committed Feb 12, 2017
1 parent 2fa5a26 commit b172103
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 54 deletions.
36 changes: 19 additions & 17 deletions Example/ExampleCropViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,13 @@ class ExampleCropViewController: IGRPhotoTweakViewController {
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

//FIXME: Customization
//self.photoView.isHighlightMask = true
//self.photoView.highlightMaskAlphaValue = 0.2
//self.maxRotationAngle = CGFloat(M_PI)
//self.isAutoSaveToLibray = true
// 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 Down Expand Up @@ -135,21 +129,29 @@ class ExampleCropViewController: IGRPhotoTweakViewController {
}

//FIXME: Themes Preview
// override func borderColor() -> UIColor {
// override open func customBorderColor() -> UIColor {
// return UIColor.red
// }
//
// override func borderWidth() -> CGFloat {
// override open func customBorderWidth() -> CGFloat {
// return 2.0
// }
//
// override func cornerBorderWidth() -> CGFloat {
// override open func customCornerBorderWidth() -> CGFloat {
// return 4.0
// }
//
// override func cornerBorderLength() -> CGFloat {
// override open func customCornerBorderLength() -> CGFloat {
// return 30.0
// }
//
// override open func customIsHighlightMask() -> Bool {
// return true
// }
//
// override open func customHighlightMaskAlphaValue() -> CGFloat {
// return 0.3
// }
}

extension ExampleCropViewController: KCHorizontalDialDelegate {
Expand Down
2 changes: 1 addition & 1 deletion Example/Resources/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<integer key="value" value="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="markCount">
<integer key="value" value="20"/>
<integer key="value" value="30"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="enableRange" value="YES"/>
<userDefinedRuntimeAttribute type="string" keyPath="verticalAlign" value="center"/>
Expand Down
2 changes: 1 addition & 1 deletion IGRPhotoTweaks.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'IGRPhotoTweaks'
spec.version = '1.0.1'
spec.version = '1.0.2'
spec.platform = :ios, '9.0'

spec.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
4 changes: 2 additions & 2 deletions IGRPhotoTweaks/CropView/IGRCropCornerLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import UIKit

class IGRCropCornerLine: UIView {
@objc public class IGRCropCornerLine: UIView {

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

Expand Down
6 changes: 3 additions & 3 deletions IGRPhotoTweaks/CropView/IGRCropCornerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import UIKit

class IGRCropCornerView: UIView {
@objc public class IGRCropCornerView: UIView {

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

Expand All @@ -20,7 +20,7 @@ class IGRCropCornerView: UIView {
setup(cornerType: type, lineWidth: lineWidth, lineLenght:lineLenght)
}

required init?(coder aDecoder: NSCoder) {
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

setup(cornerType: .upperRight, lineWidth: 2.0, lineLenght:kCropViewCornerLength)
Expand Down
4 changes: 2 additions & 2 deletions IGRPhotoTweaks/CropView/IGRCropGridLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import UIKit

class IGRCropGridLine: UIView {
@objc public class IGRCropGridLine: UIView {

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

Expand Down
4 changes: 2 additions & 2 deletions IGRPhotoTweaks/CropView/IGRCropLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import UIKit

class IGRCropLine: UIView {
@objc public class IGRCropLine: UIView {

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

Expand Down
4 changes: 2 additions & 2 deletions IGRPhotoTweaks/CropView/IGRCropMaskView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import UIKit

class IGRCropMaskView: UIView {
@objc public class IGRCropMaskView: UIView {

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

Expand Down
6 changes: 3 additions & 3 deletions IGRPhotoTweaks/CropView/IGRPhotoContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import UIKit

class IGRPhotoContentView: UIView {
@objc public class IGRPhotoContentView: UIView {

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

Expand All @@ -31,7 +31,7 @@ class IGRPhotoContentView: UIView {
}
}

override func layoutSubviews() {
override public func layoutSubviews() {
super.layoutSubviews()
self.imageView?.frame = self.bounds
}
Expand Down
37 changes: 23 additions & 14 deletions IGRPhotoTweaks/IGRPhotoTweakView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@

import UIKit

protocol IGRPhotoTweakViewCustomizationDelegate: NSObjectProtocol {
@objc public protocol IGRPhotoTweakViewCustomizationDelegate: NSObjectProtocol {
func borderColor() -> UIColor

func borderWidth() -> CGFloat

func cornerBorderWidth() -> CGFloat

func cornerBorderLength() -> CGFloat

func isHighlightMask() -> Bool
func highlightMaskAlphaValue() -> CGFloat
}

class IGRPhotoTweakView: UIView {
override class func initialize () {
@objc public class IGRPhotoTweakView: UIView {
override public class func initialize () {
self.appearance().backgroundColor = UIColor.photoTweakCanvasBackground()
}

open weak var customizationDelegate: IGRPhotoTweakViewCustomizationDelegate?

var isHighlightMask: Bool = false
var highlightMaskAlphaValue: CGFloat = 0.5

private(set) var angle: CGFloat = 0.0
private(set) var photoContentOffset = CGPoint.zero
private(set) var cropView: IGRCropView!
Expand Down Expand Up @@ -66,6 +66,7 @@ class IGRPhotoTweakView: UIView {
super.init(frame: frame)

self.image = image

self.customizationDelegate = customizationDelegate

// scale the image
Expand All @@ -82,7 +83,6 @@ class IGRPhotoTweakView: UIView {
self.centerY = self.maximumCanvasSize.height / 2.0 + kCanvasHeaderHeigth

self.scrollView = IGRPhotoScrollView(frame: bounds)
self.scrollView.updateDelegate = self
self.scrollView.center = CGPoint(x: (self.frame.width / 2.0), y: self.centerY)
self.scrollView.bounces = true
self.scrollView.layer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
Expand All @@ -96,6 +96,7 @@ class IGRPhotoTweakView: UIView {
self.scrollView.clipsToBounds = false
self.scrollView.contentSize = CGSize(width: self.scrollView.bounds.size.width,
height: self.scrollView.bounds.size.height)
self.scrollView.updateDelegate = self
self.addSubview(self.scrollView)

self.photoContentView = IGRPhotoContentView(frame: self.scrollView.bounds)
Expand Down Expand Up @@ -146,11 +147,19 @@ class IGRPhotoTweakView: UIView {
return (self.customizationDelegate?.cornerBorderLength())!
}

required init?(coder aDecoder: NSCoder) {
func isHighlightMask() -> Bool {
return (self.customizationDelegate?.isHighlightMask())!
}

func highlightMaskAlphaValue() -> CGFloat {
return (self.customizationDelegate?.highlightMaskAlphaValue())!
}

required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
override public func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if self.cropView.frame.insetBy(dx: -kCropViewHotArea, dy: -kCropViewHotArea).contains(point) &&
!self.cropView.frame.insetBy(dx: kCropViewHotArea, dy: kCropViewHotArea).contains(point) {

Expand Down Expand Up @@ -188,8 +197,8 @@ class IGRPhotoTweakView: UIView {
}

fileprivate func highlightMask(_ highlight:Bool, animate: Bool) {
if isHighlightMask {
let newAlphaValue: CGFloat = highlight ? highlightMaskAlphaValue : 1.0
if (self.isHighlightMask()) {
let newAlphaValue: CGFloat = highlight ? self.highlightMaskAlphaValue() : 1.0

let animationBlock: ((_: Void) -> Void)? = {(_: Void) -> Void in
self.topMask.alpha = newAlphaValue
Expand Down Expand Up @@ -301,15 +310,15 @@ class IGRPhotoTweakView: UIView {
}

extension IGRPhotoTweakView : UIScrollViewDelegate {
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
public func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return self.photoContentView
}

func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
public func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
self.cropView.updateCropLines(true)
}

func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {
public func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {
self.manualZoomed = true
self.cropView.dismissCropLines()
}
Expand Down
46 changes: 39 additions & 7 deletions IGRPhotoTweaks/IGRPhotoTweakViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,54 @@ import Photos
present(ac, animated: true, completion: nil)
}
}
}

extension IGRPhotoTweakViewController : IGRPhotoTweakViewCustomizationDelegate {
func borderColor() -> UIColor {

open func customBorderColor() -> UIColor {
return UIColor.cropLine()
}

func borderWidth() -> CGFloat {
open func customBorderWidth() -> CGFloat {
return 1.0
}

func cornerBorderWidth() -> CGFloat {
open func customCornerBorderWidth() -> CGFloat {
return kCropViewCornerWidth
}

func cornerBorderLength() -> CGFloat {
open func customCornerBorderLength() -> CGFloat {
return kCropViewCornerLength
}

open func customIsHighlightMask() -> Bool {
return true
}

open func customHighlightMaskAlphaValue() -> CGFloat {
return 0.3
}
}

extension IGRPhotoTweakViewController : IGRPhotoTweakViewCustomizationDelegate {
public func borderColor() -> UIColor {
return self.customBorderColor()
}

public func borderWidth() -> CGFloat {
return self.customBorderWidth()
}

public func cornerBorderWidth() -> CGFloat {
return self.customCornerBorderWidth()
}

public func cornerBorderLength() -> CGFloat {
return self.customCornerBorderLength()
}

public func isHighlightMask() -> Bool {
return self.customIsHighlightMask()
}

public func highlightMaskAlphaValue() -> CGFloat {
return self.customHighlightMaskAlphaValue()
}
}

0 comments on commit b172103

Please sign in to comment.