/
YPHelper.swift
92 lines (75 loc) 路 3.42 KB
/
YPHelper.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// YPHelper.swift
// YPImgePicker
//
// Created by Sacha Durand Saint Omer on 02/11/16.
// Copyright 漏 2016 Yummypets. All rights reserved.
//
import Foundation
import UIKit
import Photos
internal func ypLocalized(_ str: String) -> String {
return NSLocalizedString(str,
tableName: nil,
bundle: Bundle(for: YPPickerVC.self),
value: "",
comment: "")
}
internal func imageFromBundle(_ named: String) -> UIImage {
return UIImage(named: named, in: Bundle(for: YPPickerVC.self), compatibleWith: nil) ?? UIImage()
}
struct YPHelper {
static func changeBackButtonIcon(_ controller: UIViewController) {
if YPConfig.icons.shouldChangeDefaultBackButtonIcon {
let backButtonIcon = YPConfig.icons.backButtonIcon
controller.navigationController?.navigationBar.backIndicatorImage = backButtonIcon
controller.navigationController?.navigationBar.backIndicatorTransitionMaskImage = backButtonIcon
}
}
static func changeBackButtonTitle(_ controller: UIViewController) {
if YPConfig.icons.hideBackButtonTitle {
controller.navigationItem.backBarButtonItem = UIBarButtonItem(title: "",
style: .plain,
target: nil,
action: nil)
}
}
static func configureFocusView(_ v: UIView) {
v.alpha = 0.0
v.backgroundColor = UIColor.clear
v.layer.borderColor = UIColor(r: 204, g: 204, b: 204).cgColor
v.layer.borderWidth = 1.0
v.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
}
static func animateFocusView(_ v: UIView) {
UIView.animate(withDuration: 0.8, delay: 0.0, usingSpringWithDamping: 0.8,
initialSpringVelocity: 3.0, options: UIViewAnimationOptions.curveEaseIn,
animations: {
v.alpha = 1.0
v.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
}, completion: { _ in
v.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
v.removeFromSuperview()
})
}
static func formattedStrigFrom(_ timeInterval: TimeInterval) -> String {
let interval = Int(timeInterval)
let seconds = interval % 60
let minutes = (interval / 60) % 60
return String(format: "%02d:%02d", minutes, seconds)
}
public static func unwrapImageMetaAssets(asset : PHAsset) -> [String : Any]?{
let imageRequestOptions = PHImageRequestOptions()
imageRequestOptions.isSynchronous = true
var returnValue = [String : Any]()
PHImageManager.default().requestImageData(for: asset, options: imageRequestOptions) { (data, dataUTI, orientation, info) in
returnValue = self.metadataForImageData(data: data!)
}
return returnValue
}
private static func metadataForImageData(data : Data) -> [String : Any]{
let imageSource = CGImageSourceCreateWithData(data as CFData, nil)
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource!, 0, nil)
return imageProperties! as! [String : Any]
}
}