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()
|
||||
|
||||
public let zoom = MacawZoom()
|
||||
public lazy var zoom = MacawZoom(view: self)
|
||||
|
||||
open var node: Node {
|
||||
get { return drawingView.node }
|
||||
@ -77,7 +77,7 @@ open class MacawView: MView, MGestureRecognizerDelegate {
|
||||
self.node = node
|
||||
self.renderer = RenderUtils.createNodeRenderer(node, view: drawingView)
|
||||
|
||||
zoom.initialize(view: self, onChange: onZoomChange)
|
||||
zoom.initialize(onChange: onZoomChange)
|
||||
initializeView()
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ open class MacawView: MView, MGestureRecognizerDelegate {
|
||||
public override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
zoom.initialize(view: self, onChange: onZoomChange)
|
||||
zoom.initialize(onChange: onZoomChange)
|
||||
initializeView()
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,8 @@ import AppKit
|
||||
|
||||
open class MacawZoom {
|
||||
|
||||
private var view: MacawView!
|
||||
private var onChange: ((Transform) -> Void)!
|
||||
private unowned let view: MacawView
|
||||
private var onChange: ((Transform) -> Void)?
|
||||
private var touches = [TouchData]()
|
||||
private var zoomData = ZoomData()
|
||||
|
||||
@ -25,6 +25,10 @@ open class MacawZoom {
|
||||
private var trackScale = false
|
||||
private var trackRotate = false
|
||||
|
||||
init(view: MacawView) {
|
||||
self.view = view
|
||||
}
|
||||
|
||||
open func enable(move: Bool = true, scale: Bool = true, rotate: Bool = false) {
|
||||
trackMove = move
|
||||
trackScale = scale
|
||||
@ -47,11 +51,10 @@ open class MacawZoom {
|
||||
let s = scale ?? zoomData.scale
|
||||
let a = angle ?? zoomData.angle
|
||||
zoomData = ZoomData(offset: o, scale: s, angle: a)
|
||||
onChange(zoomData.transform())
|
||||
onChange?(zoomData.transform())
|
||||
}
|
||||
|
||||
func initialize(view: MacawView, onChange: @escaping ((Transform) -> Void)) {
|
||||
self.view = view
|
||||
func initialize(onChange: @escaping (Transform) -> Void) {
|
||||
self.onChange = onChange
|
||||
}
|
||||
|
||||
@ -63,7 +66,7 @@ open class MacawZoom {
|
||||
|
||||
func touchesMoved(_ touches: Set<MTouch>) {
|
||||
let zoom = cleanTouches() ?? getNewZoom()
|
||||
onChange(zoom.transform())
|
||||
onChange?(zoom.transform())
|
||||
}
|
||||
|
||||
func touchesEnded(_ touches: Set<MTouch>) {
|
||||
|
Loading…
Reference in New Issue
Block a user