This repository was archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 380
Expand file tree
/
Copy pathViewController.swift
More file actions
86 lines (70 loc) · 3 KB
/
ViewController.swift
File metadata and controls
86 lines (70 loc) · 3 KB
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
//
// ViewController.swift
// ALCameraViewController
//
// Created by Alex Littlejohn on 2015/06/17.
// Copyright (c) 2015 zero. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var libraryEnabled: Bool = true
var croppingEnabled: Bool = false
var allowResizing: Bool = true
var allowMoving: Bool = false
var minimumSize: CGSize = CGSize(width: 60, height: 60)
var croppingParameters: CroppingParameters {
return CroppingParameters(isEnabled: croppingEnabled, allowResizing: allowResizing, allowMoving: allowMoving, minimumSize: minimumSize)
}
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var croppingParametersView: UIView!
@IBOutlet weak var minimumSizeLabel: UILabel!
@IBOutlet weak var multipleSelectionSwitch: UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
self.imageView.contentMode = .scaleAspectFit
}
@IBAction func openCamera(_ sender: Any) {
let cameraViewController = CameraViewController(croppingParameters: croppingParameters, allowsLibraryAccess: libraryEnabled) { [weak self] image, asset in
self?.imageView.image = image
self?.dismiss(animated: true, completion: nil)
}
present(cameraViewController, animated: true, completion: nil)
}
@IBAction func openLibrary(_ sender: Any) {
if multipleSelectionSwitch.isOn {
let libraryViewController = CameraViewController.imagePickerViewController(completion: { [weak self] assets in
if let assets = assets {
let images = ImageFetcher.resolveAssets(assets, size: largestPhotoSize())
self?.imageView.image = images.last
}
self?.dismiss(animated: true, completion: nil)
})
present(libraryViewController, animated: true, completion: nil)
} else {
let libraryViewController = CameraViewController.imagePickerViewController(croppingParameters: croppingParameters) {
[weak self] image, asset in
self?.imageView.image = image
self?.dismiss(animated: true, completion: nil)
}
present(libraryViewController, animated: true, completion: nil)
}
}
@IBAction func libraryChanged(_ sender: Any) {
libraryEnabled = !libraryEnabled
}
@IBAction func croppingChanged(_ sender: UISwitch) {
croppingEnabled = sender.isOn
croppingParametersView.isHidden = !sender.isOn
}
@IBAction func resizingChanged(_ sender: UISwitch) {
allowResizing = sender.isOn
}
@IBAction func movingChanged(_ sender: UISwitch) {
allowMoving = sender.isOn
}
@IBAction func minimumSizeChanged(_ sender: UISlider) {
let newValue = sender.value
minimumSize = CGSize(width: CGFloat(newValue), height: CGFloat(newValue))
minimumSizeLabel.text = "Minimum size: \(newValue.rounded())"
}
}