-
Notifications
You must be signed in to change notification settings - Fork 3
/
CustomLeonImages.swift
118 lines (93 loc) · 3.95 KB
/
CustomLeonImages.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// CustomLeonImages.swift
// LeonExample
//
// Created by yusef naser on 11/9/19.
// Copyright © 2019 yusef naser. All rights reserved.
//
import UIKit
import Leon
class CustomLeonImages : LeonImages {
var isTapped = false
// creating topView
lazy var headerView : UIView = {
let v = UIView()
v.backgroundColor = #colorLiteral(red: 0.2470588235, green: 0.7725490196, blue: 0.9411764706, alpha: 0.5)
let b = UIButton()
b.layer.cornerRadius = 35 / 2
b.setTitle("close", for: .normal)
b.addTarget(self , action: #selector(dismissController), for: .touchUpInside )
v.addSubview(b)
b.translatesAutoresizingMaskIntoConstraints = false
b.leadingAnchor.constraint(equalTo: v.leadingAnchor , constant: 16).isActive = true
if #available(iOS 11.0, *) {
b.topAnchor.constraint(equalTo: v.safeAreaLayoutGuide.topAnchor , constant: 16).isActive = true
} else {
b.topAnchor.constraint(equalTo: v.topAnchor , constant: 16).isActive = true
}
let l = UILabel()
l.text = "Title Header"
l.textColor = .white
v.addSubview(l)
l.translatesAutoresizingMaskIntoConstraints = false
l.centerXAnchor.constraint(equalTo: v.centerXAnchor , constant: 0).isActive = true
l.centerYAnchor.constraint(equalTo: v.centerYAnchor , constant: 0).isActive = true
return v
}()
// creating bottomView
lazy var footerView : UIView = {
let v = UIView()
v.backgroundColor = #colorLiteral(red: 0.2588235294, green: 0.8705882353, blue: 0.8823529412, alpha: 0.5)
return v
}()
override func viewDidLoad() {
super.viewDidLoad()
// add header view and footerView on view
self.view.addSubview(headerView)
self.view.addSubview(footerView)
// set constraints for headerView
headerView.translatesAutoresizingMaskIntoConstraints = false
headerView.topAnchor.constraint(equalTo: self.view.topAnchor , constant: 0).isActive = true
headerView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 0).isActive = true
headerView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor , constant: 0).isActive = true
headerView.heightAnchor.constraint(equalToConstant: 150).isActive = true
// set constraints for footerView
footerView.translatesAutoresizingMaskIntoConstraints = false
footerView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor , constant: 0).isActive = true
footerView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor , constant: 0).isActive = true
footerView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor , constant: 0).isActive = true
footerView.heightAnchor.constraint(equalToConstant: 150).isActive = true
}
@objc private func dismissController(){
dismissLeon()
}
@objc override func singleTapped() {
if !isTapped {
isTapped = true
startPanGesture()
}else {
isTapped = false
returnImageToCenter()
}
}
// get pageIndex that appear on leonImages
override var pageIndex: Int {
didSet {
print("pageIndex : \(self.pageIndex)")
}
}
// excute this function when user began move with panGesture
override func startPanGesture() {
UIView.animate(withDuration: 0.3 ) { [weak self] in
self?.headerView.alpha = 0
self?.footerView.alpha = 0
}
}
// excute this function when use leave panGesture and image return in center of screen
override func returnImageToCenter() {
UIView.animate(withDuration: 0.3 ) { [weak self] in
self?.headerView.alpha = 1
self?.footerView.alpha = 1
}
}
}