mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-11 05:05:23 +03:00
Fixed retain cycle between MacawView and MacawZoom
This commit is contained in:
parent
cfb97d6f73
commit
2181401dbb
@ -15,7 +15,7 @@ open class MacawView: MView, MGestureRecognizerDelegate {
|
|||||||
|
|
||||||
internal var drawingView = DrawingView()
|
internal var drawingView = DrawingView()
|
||||||
|
|
||||||
public let zoom = MacawZoom()
|
public lazy var zoom = MacawZoom(view: self)
|
||||||
|
|
||||||
open var node: Node {
|
open var node: Node {
|
||||||
get { return drawingView.node }
|
get { return drawingView.node }
|
||||||
@ -77,7 +77,7 @@ open class MacawView: MView, MGestureRecognizerDelegate {
|
|||||||
self.node = node
|
self.node = node
|
||||||
self.renderer = RenderUtils.createNodeRenderer(node, view: drawingView)
|
self.renderer = RenderUtils.createNodeRenderer(node, view: drawingView)
|
||||||
|
|
||||||
zoom.initialize(view: self, onChange: onZoomChange)
|
zoom.initialize(onChange: onZoomChange)
|
||||||
initializeView()
|
initializeView()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ open class MacawView: MView, MGestureRecognizerDelegate {
|
|||||||
public override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
|
|
||||||
zoom.initialize(view: self, onChange: onZoomChange)
|
zoom.initialize(onChange: onZoomChange)
|
||||||
initializeView()
|
initializeView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,14 +16,18 @@ import AppKit
|
|||||||
|
|
||||||
open class MacawZoom {
|
open class MacawZoom {
|
||||||
|
|
||||||
private var view: MacawView!
|
private unowned let view: MacawView
|
||||||
private var onChange: ((Transform) -> Void)!
|
private var onChange: ((Transform) -> Void)?
|
||||||
private var touches = [TouchData]()
|
private var touches = [TouchData]()
|
||||||
private var zoomData = ZoomData()
|
private var zoomData = ZoomData()
|
||||||
|
|
||||||
private var trackMove = false
|
private var trackMove = false
|
||||||
private var trackScale = false
|
private var trackScale = false
|
||||||
private var trackRotate = false
|
private var trackRotate = false
|
||||||
|
|
||||||
|
init(view: MacawView) {
|
||||||
|
self.view = view
|
||||||
|
}
|
||||||
|
|
||||||
open func enable(move: Bool = true, scale: Bool = true, rotate: Bool = false) {
|
open func enable(move: Bool = true, scale: Bool = true, rotate: Bool = false) {
|
||||||
trackMove = move
|
trackMove = move
|
||||||
@ -47,11 +51,10 @@ open class MacawZoom {
|
|||||||
let s = scale ?? zoomData.scale
|
let s = scale ?? zoomData.scale
|
||||||
let a = angle ?? zoomData.angle
|
let a = angle ?? zoomData.angle
|
||||||
zoomData = ZoomData(offset: o, scale: s, angle: a)
|
zoomData = ZoomData(offset: o, scale: s, angle: a)
|
||||||
onChange(zoomData.transform())
|
onChange?(zoomData.transform())
|
||||||
}
|
}
|
||||||
|
|
||||||
func initialize(view: MacawView, onChange: @escaping ((Transform) -> Void)) {
|
func initialize(onChange: @escaping (Transform) -> Void) {
|
||||||
self.view = view
|
|
||||||
self.onChange = onChange
|
self.onChange = onChange
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +66,7 @@ open class MacawZoom {
|
|||||||
|
|
||||||
func touchesMoved(_ touches: Set<MTouch>) {
|
func touchesMoved(_ touches: Set<MTouch>) {
|
||||||
let zoom = cleanTouches() ?? getNewZoom()
|
let zoom = cleanTouches() ?? getNewZoom()
|
||||||
onChange(zoom.transform())
|
onChange?(zoom.transform())
|
||||||
}
|
}
|
||||||
|
|
||||||
func touchesEnded(_ touches: Set<MTouch>) {
|
func touchesEnded(_ touches: Set<MTouch>) {
|
||||||
|
Loading…
Reference in New Issue
Block a user