1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-09-11 05:05:23 +03:00

Fix some examples

This commit is contained in:
Alisa Mylnikova 2020-04-17 15:55:40 +07:00
parent 9a73bc012f
commit bb47def337
2 changed files with 25 additions and 34 deletions

View File

@ -115,13 +115,16 @@ extension AnimationProducer {
// MARK: - Combine animation // MARK: - Combine animation
func addCombineAnimation(_ combineAnimation: Animation, _ context: AnimationContext) { func addCombineAnimation(_ combineAnimation: Animation, _ context: AnimationContext) {
guard let combine = combineAnimation as? CombineAnimation, guard let combine = combineAnimation as? CombineAnimation,
let _ = combine.nodeRenderer,
let node = combine.node else { let node = combine.node else {
return return
} }
var animations = combine.animations var animations = combine.animations
let childAnimations = createChildAnimations(combine) as! [BasicAnimation] if let _ = combine.node?.bounds, let _ = combine.toNodes.group().bounds {
animations.append(contentsOf: childAnimations) let childAnimations = createChildAnimations(combine) as! [BasicAnimation]
animations.append(contentsOf: childAnimations)
}
// Reversing // Reversing
if combine.autoreverses { if combine.autoreverses {

View File

@ -74,9 +74,8 @@ open class MacawView: MView {
@objc public init?(node: Node, coder aDecoder: NSCoder) { @objc public init?(node: Node, coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
if let drawingView = DrawingView(node: node, coder: aDecoder) { self.node = node
self.drawingView = drawingView self.renderer = RenderUtils.createNodeRenderer(node, view: drawingView)
}
zoom.initialize(view: self, onChange: onZoomChange) zoom.initialize(view: self, onChange: onZoomChange)
} }
@ -84,14 +83,13 @@ open class MacawView: MView {
public convenience init(node: Node, frame: CGRect) { public convenience init(node: Node, frame: CGRect) {
self.init(frame: frame) self.init(frame: frame)
self.drawingView = DrawingView(node: node, frame: frame) self.node = node
self.renderer = RenderUtils.createNodeRenderer(node, view: drawingView)
} }
public override init(frame: CGRect) { public override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
self.drawingView = DrawingView(frame: frame)
zoom.initialize(view: self, onChange: onZoomChange) zoom.initialize(view: self, onChange: onZoomChange)
} }
@ -107,21 +105,27 @@ open class MacawView: MView {
initializeView() initializeView()
} }
open override func layoutSubviews() {
super.layoutSubviews()
drawingView.frame = self.bounds
}
func initializeView() { func initializeView() {
if !self.subviews.contains(drawingView) { if !self.subviews.contains(drawingView) {
self.backgroundColor = .white if self.backgroundColor == nil {
self.clipsToBounds = true self.backgroundColor = .white
}
drawingView.removeFromSuperview()
self.addSubview(drawingView) self.addSubview(drawingView)
drawingView.backgroundColor = .white drawingView.backgroundColor = .clear
drawingView.isUserInteractionEnabled = false
drawingView.initializeView() drawingView.initializeView()
drawingView.translatesAutoresizingMaskIntoConstraints = false #if os(iOS)
drawingView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true self.clipsToBounds = true
drawingView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true drawingView.isUserInteractionEnabled = false
drawingView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true #endif
drawingView.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
} }
let tapRecognizer = MTapGestureRecognizer(target: drawingView, action: #selector(DrawingView.handleTap(recognizer:))) let tapRecognizer = MTapGestureRecognizer(target: drawingView, action: #selector(DrawingView.handleTap(recognizer:)))
@ -277,24 +281,8 @@ internal class DrawingView: MView, MGestureRecognizerDelegate {
self.context = RenderContext(view: self) self.context = RenderContext(view: self)
} }
@objc public convenience required init?(coder aDecoder: NSCoder) { @objc public required init?(coder aDecoder: NSCoder) {
self.init(node: Group(), coder: aDecoder)
}
@objc public init?(node: Node, coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
self.node = node
self.renderer = RenderUtils.createNodeRenderer(node, view: self)
backgroundColor = .white
}
public convenience init(node: Node, frame: CGRect) {
self.init(frame: frame)
self.node = node
self.renderer = RenderUtils.createNodeRenderer(node, view: self)
backgroundColor = .white
} }
public override init(frame: CGRect) { public override init(frame: CGRect) {