Skip to content

Commit 0fbd931

Browse files
Test Add new type Fave
1 parent a7b191f commit 0fbd931

File tree

10 files changed

+291
-87
lines changed

10 files changed

+291
-87
lines changed

Example/ButtonClickStyle/UI/Button/JustPink/JustPinkButtonView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ class JustPinkButtonView: BtnView {
9090
// views = nil
9191
views = [subMainView]
9292
}
93+
if type == ButtonClick._Style.fave.rawValue {
94+
views = [mainDetailsView, gradientView]
95+
}
9396

9497
mainDetailsView.setNeedsLayout()
9598
mainShadowView.setNeedsLayout()

Example/ButtonClickStyle/UI/Screen/ButtonList/ButtonListViewController.storyboard

Lines changed: 107 additions & 82 deletions
Large diffs are not rendered by default.

Example/ButtonClickStyle/UI/Screen/ButtonList/ButtonListViewController.swift

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ class ButtonListViewController: StoryboardController {
1212
@IBOutlet var buttonLayerExampleView: ButtonLayerExampleView?
1313
@IBOutlet var buttonTypePicker: UIPickerView!
1414
@IBOutlet var animationTypePicker: UIPickerView!
15-
var colorSelected: UIColor?
1615

1716
@IBOutlet var animationValueLabel: UILabel!
1817
@IBOutlet var animationValueSlider: UISlider!
1918
var animationTypeLast: Int = 0
2019
var buttonTypeLast: Int = 0
2120

21+
22+
23+
@IBOutlet var colorClearButton: UIButton!
24+
var colorChanging: Bool = false
25+
@IBOutlet var colorDesignableView: DesignableView!
26+
var colorSelected: UIColor?
27+
let colorPicker = UIColorPickerViewController()
28+
29+
2230
let buttonTypes = [
2331
"JustPink",
2432
"No shadow",
@@ -40,6 +48,25 @@ class ButtonListViewController: StoryboardController {
4048
]
4149

4250

51+
@IBAction func colorPickerAction(_ sender: Any) {
52+
resetAllColorChangeFlags()
53+
colorChanging = true
54+
present(colorPicker, animated: true, completion: nil)
55+
}
56+
57+
@IBAction func buttonColorClear(_ sender: Any) {
58+
colorSelected = nil
59+
colorClearButton.isHidden = true
60+
colorDesignableView.fillColor = .clear
61+
colorDesignableView.setNeedsLayout()
62+
updateButtons()
63+
}
64+
65+
66+
@IBAction func buttonReloadAction(_ sender: Any) {
67+
updateButtons()
68+
}
69+
4370
//MARK: - viewDidAppear
4471

4572
@IBAction func exampleButtonsScreenButtonAction(_ sender: UIButton) {
@@ -78,6 +105,8 @@ class ButtonListViewController: StoryboardController {
78105
override func viewDidLoad() {
79106
super.viewDidLoad()
80107

108+
colorPicker.delegate = self
109+
81110
animationValueSlider.addTarget(self, action: #selector(onSliderValChanged(slider:event:)), for: .valueChanged)
82111

83112
buttonTypePicker.delegate = self
@@ -348,3 +377,31 @@ extension ButtonListViewController: UIPickerViewDelegate {
348377
updateButtons()
349378
}
350379
}
380+
381+
382+
extension ButtonListViewController: UIColorPickerViewControllerDelegate {
383+
384+
func colorPickerViewControllerDidSelectColor(_ viewController: UIColorPickerViewController) {
385+
386+
if colorChanging
387+
{
388+
colorSelected = viewController.selectedColor
389+
}
390+
colorClearButton.isHidden = (colorSelected == nil) || (colorSelected == .clear)
391+
}
392+
393+
func colorPickerViewControllerDidFinish(_ viewController: UIColorPickerViewController)
394+
{
395+
updateButtons()
396+
colorDesignableView.fillColor = colorSelected
397+
colorDesignableView.setNeedsLayout()
398+
resetAllColorChangeFlags()
399+
400+
} // ends colorPickerViewControllerDidFinish
401+
402+
func resetAllColorChangeFlags()
403+
{
404+
colorChanging = false
405+
406+
} // ends resetAllColorChangeFlags
407+
}

Example/ButtonClickStyle/UI/Screen/ExampleClickStyleAnimations/ExampleAnimationsViewController.storyboard

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
<dependencies>
55
<deployment identifier="iOS"/>
66
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
7+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
78
<capability name="System colors in document resources" minToolsVersion="11.0"/>
89
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
910
</dependencies>
1011
<scenes>
1112
<!-- -->
1213
<scene sceneID="xg4-tC-VA3">
1314
<objects>
14-
<viewController storyboardIdentifier="ExampleAnimationsViewController" title=" " useStoryboardIdentifierAsRestorationIdentifier="YES" id="t78-RV-KY0" customClass="ExampleAnimationsViewController" customModule="ButtonClickStyle" customModuleProvider="target" sceneMemberID="viewController">
15+
<viewController storyboardIdentifier="ExampleAnimationsViewController" title=" " useStoryboardIdentifierAsRestorationIdentifier="YES" id="t78-RV-KY0" customClass="ExampleAnimationsViewController" customModule="ButtonClickStyle_Example" customModuleProvider="target" sceneMemberID="viewController">
1516
<view key="view" contentMode="scaleToFill" id="9Ed-Au-iL3">
1617
<rect key="frame" x="0.0" y="0.0" width="1366" height="1024"/>
1718
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -110,7 +111,7 @@
110111
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="gyc-WS-Y1V">
111112
<rect key="frame" x="20" y="188" width="210" height="31"/>
112113
<subviews>
113-
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="7KF-CK-r9N" customClass="DesignableView" customModule="ButtonClickStyle" customModuleProvider="target">
114+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="7KF-CK-r9N" customClass="DesignableView" customModule="ButtonClickStyle_Example" customModuleProvider="target">
114115
<rect key="frame" x="161" y="0.5" width="51" height="30"/>
115116
<subviews>
116117
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ESl-Gn-TeW">
@@ -254,6 +255,7 @@
254255
<nil key="highlightedColor"/>
255256
</label>
256257
</subviews>
258+
<viewLayoutGuide key="safeArea" id="0Fv-fj-hvd"/>
257259
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
258260
<constraints>
259261
<constraint firstAttribute="bottom" secondItem="1t5-3Y-2I6" secondAttribute="bottom" constant="30" id="03u-ZG-9wi"/>

Source/ButtonClickStyle/Animations/UIView+AnimationPulsate.swift

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,102 @@
77

88
import UIKit
99

10+
11+
12+
extension UIView {
13+
14+
public func buttonClickStyleFave(mainView: UIView, secondView: UIView, color: UIColor? = nil, value: CGFloat, duration: CGFloat) {
15+
let maxSize = max(mainView.wwidth, mainView.hheight)
16+
let _y = (mainView.hheight / 2) - (maxSize / 2)
17+
let _x = (mainView.wwidth / 2) - (maxSize / 2)
18+
19+
mainView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
20+
21+
let clr = color ?? UIColor.black
22+
23+
let circle = UIView(frame: .init(x: _x, y: _y, width: maxSize, height: maxSize))
24+
circle.layer.cornerRadius = maxSize / 2
25+
circle.backgroundColor = .clear // color ?? UIColor.black
26+
circle.layer.borderWidth = maxSize / 2
27+
circle.layer.borderColor = clr.cgColor
28+
circle.alpha = 0.35
29+
30+
31+
32+
secondView .addSubview(circle)
33+
34+
main(delay: 0.25) {
35+
36+
let borderWidthAnimation: CABasicAnimation = CABasicAnimation(keyPath: "borderWidth")
37+
borderWidthAnimation.fromValue = circle.layer.borderWidth
38+
borderWidthAnimation.toValue = 0
39+
borderWidthAnimation.duration = 0.15
40+
circle.layer.add(borderWidthAnimation, forKey: "borderWidth")
41+
circle.layer.borderWidth = 0
42+
43+
}
44+
45+
// let pulse = CASpringAnimation(keyPath: "transform.scale")
46+
// pulse.duration = 0.45
47+
// pulse.fromValue = 0.01
48+
// pulse.toValue = 1.0
49+
// pulse.autoreverses = true
50+
// pulse.repeatCount = 2
51+
// pulse.initialVelocity = 6.0
52+
// pulse.damping = 0.4
53+
// circle.layer.add(pulse, forKey: "pulse")
54+
55+
circle.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
56+
57+
// UIView.animate(withDuration: 0.12) {
58+
// circle.transform = .identity
59+
// }
60+
61+
UIView.animate(withDuration: 0.45,
62+
delay: 0.0,
63+
usingSpringWithDamping: 0.8,
64+
initialSpringVelocity: 6,
65+
options: [.curveEaseOut],
66+
animations: {
67+
circle.transform = .identity
68+
// circle.alpha = 0.65
69+
}, completion: nil)
70+
71+
72+
73+
74+
75+
76+
// UIView.animate(withDuration: 0.15, // 0.4,
77+
// delay: 0,
78+
// usingSpringWithDamping: 0.8,
79+
// initialSpringVelocity: 6.0,
80+
// options: [.allowUserInteraction],
81+
// animations: {
82+
// circle.transform = .identity
83+
// circle.alpha = 0.65
84+
// }, completion: { fin in
85+
//
86+
// })
87+
88+
UIView.animate(withDuration: 0.35, // 0.4,
89+
delay: 0.32,
90+
usingSpringWithDamping: 0.38,
91+
initialSpringVelocity: 10.0,
92+
options: [.allowUserInteraction],
93+
animations: {
94+
mainView.transform = .identity
95+
mainView.alpha = 1.0
96+
circle.alpha = 0.0
97+
}, completion: { fin in
98+
99+
100+
circle.removeFromSuperview()
101+
})
102+
}
103+
}
104+
105+
10106
extension UIView {
11107

12108

Source/ButtonClickStyle/ButtonClickStyleAddViewsAnimation.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,19 @@ extension UIButton {
185185
}
186186

187187
switch style {
188+
case .fave(let power, let color):
189+
if event == .touchDown {
190+
if views.count > 1 {
191+
self.buttonClickStyleFave(mainView: views[1], secondView: views[0], color: color, value: power, duration: dur)
192+
}
193+
}
194+
188195
case .press(let power):
189196

190197
if views.count > 0 {
191198
views[0].buttonClickStylePress(duration: dur, cornRadius: radius, value: power, shadow: false, visible: event != .touchDown)
192199
}
200+
193201
// if views.count > 1 {
194202
// views[1].press(duration: dur, cornRadius: radius, value: 0.5, shadow: true, visible: event != .touchDown)
195203
// }

Source/ButtonClickStyle/Style/ButtonClickStyle.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extension ButtonClick {
2323
case pulsate( _ power: CGFloat = vDef, new: Bool = false) // MOVE Pulsate
2424
case shake( _ power: CGFloat = vDef, new: Bool = false) // MOVE Shake
2525
case androidClickable(_ alpha: CGFloat = vDef, color: UIColor? = nil) // ADD Android Clickable
26+
case fave( _ power: CGFloat = vDef, color: UIColor? = nil) // Fave
2627

2728
//MARK: All Cases, Indxs & Names
2829

@@ -43,6 +44,7 @@ extension ButtonClick {
4344
.shake(new: true),
4445
.androidClickable(),
4546
.androidClickable(color: .random()),
47+
.fave(vDef, color: .random())
4648
]
4749

4850
public func typeEasy() -> _Style {
@@ -74,6 +76,7 @@ extension ButtonClick {
7476
: "Shake"
7577
case .androidClickable(_, let color): return color == nil ? "AndroidClickable"
7678
: "AndroidClickable Color"
79+
case .fave(_,_): return "Fave"
7780
}
7881
}
7982

@@ -89,7 +92,8 @@ extension ButtonClick {
8992
case .pulsate(_,_),
9093
.press(_),
9194
.shake(_,_): return .move
92-
case .androidClickable(_,_): return .android
95+
case .androidClickable(_,_): return .tapGesture
96+
case .fave(_,_): return .tapGesture
9397
}
9498
}
9599

@@ -116,6 +120,7 @@ extension ButtonClick {
116120
: 10
117121
case .androidClickable(_, let color): return color == nil ? 11
118122
: 12
123+
case .fave(_, _): return 13
119124
}
120125
}
121126

@@ -132,6 +137,7 @@ extension ButtonClick {
132137
case .color(_, _): return 0.3 // .ms300
133138
case .colorFlat(_, _): return 0.3 // .ms300
134139
case .androidClickable(_, _): return 1.0 // .s1
140+
case .fave(_, _): return 0.4
135141
}
136142
}
137143

@@ -164,6 +170,7 @@ extension ButtonClick {
164170
case 10: return .shake(a ?? 0.15, new: true)
165171
case 11: return .androidClickable(v, color: nil)
166172
case 12: return .androidClickable(v, color: color ?? UIColor.random())
173+
case 13: return .fave(v, color: color ?? UIColor.random())
167174
default: return .alpha(v)
168175
}
169176
}()

Source/ButtonClickStyle/Style/ButtonClickStyleBase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension ButtonClick {
1414
case move = "Move"
1515
case add = "Add"
1616
case addHide = "Add & Hide"
17-
case android = "TapGesture.Pulse"
17+
case tapGesture = "TapGesture.Pulse"
1818
case none = ""
1919
}
2020
}

Source/ButtonClickStyle/Style/ButtonClickStyleEmoji.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ extension ButtonClick.Style {
2020
case .pulsate(_, let new): return new ? "🆕" : ""
2121
case .shake(_, let new): return new ? "🆕" : ""
2222
case .androidClickable(_, let color): return color == nil ? "" : ""
23+
case .fave(_, _): return "🆕"
24+
2325
}
2426
}
2527

@@ -34,6 +36,7 @@ extension ButtonClick.Style {
3436
case .pulsate(_, _): return "💢"
3537
case .shake(_, _): return "🔛"
3638
case .androidClickable(_, _): return "🧿"
39+
case .fave(_, _): return ""
3740
}
3841
}
3942

@@ -48,6 +51,7 @@ extension ButtonClick.Style {
4851
case .pulsate(_, _): return "♻️"
4952
case .shake(_, _): return "♻️"
5053
case .androidClickable(_, _): return ""
54+
case .fave(_, _): return ""
5155
}
5256
}
5357

@@ -63,6 +67,7 @@ extension ButtonClick.Style {
6367
case .pulsate(_, let new): return new ? "" : ""
6468
case .shake(_, let new): return new ? "" : ""
6569
case .androidClickable(_, let color): return color == nil ? "⚫️" : "🔵"
70+
case .fave(_, _): return "🔵"
6671
}
6772
}
6873

Source/ButtonClickStyle/Style/ButtonClickStyleShort.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ extension ButtonClick {
2525
case shakeNew
2626
case androidClickable
2727
case androidClickableDark
28+
case fave
2829
}
2930
}

0 commit comments

Comments
 (0)