-
Notifications
You must be signed in to change notification settings - Fork 0
/
SliderVC.swift
65 lines (45 loc) · 1.33 KB
/
SliderVC.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
//
// SliderVC.swift
// pinknoise
//
// Created by Adam Tait on 2/20/18.
// Copyright © 2018 Sisterical Inc. All rights reserved.
//
import Foundation
import AsyncDisplayKit
class SliderVC : ASViewController<ASDisplayNode>
{
let p : MutableProperty<Float>
var o : Observable.Ref? = nil
let slider = UISlider(frame: .zero)
// initializers
init(property: MutableProperty<Float>)
{
self.p = property
let s = self.slider
super.init(node: ASDisplayNode { () -> UIView in
return s
})
self.node.backgroundColor = .white
self.update()
self.slider.addTarget(self, action: #selector(changed), for: .valueChanged)
self.o = p.addObserver(propertyChanged)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// observers
func propertyChanged(_ o: Observable) { update() }
@objc func changed()
{
_ = self.o?.remove() // no need to update with the same value
let v = self.slider.value
self.p.set(v)
self.o = self.p.addObserver(propertyChanged)
}
// mutators
func update()
{
slider.setValue(self.p.get()!, animated: true)
}
}