mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-11 13:15:35 +03:00
Add TransformExampleView
This commit is contained in:
parent
c00ebecdee
commit
1aebc5ddf1
@ -23,6 +23,7 @@
|
||||
574EC4441CBB60AF0063F317 /* AnimationsExampleController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 574EC4431CBB60AF0063F317 /* AnimationsExampleController.swift */; };
|
||||
575129B61CBD14AF00BD3C2E /* AnimationsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 575129B51CBD14AF00BD3C2E /* AnimationsView.swift */; };
|
||||
578791A11CEDCE8B008D85A1 /* tree.svg in Resources */ = {isa = PBXBuildFile; fileRef = 578791A01CEDCE8B008D85A1 /* tree.svg */; };
|
||||
58E4D50C1D841C6E00EC8815 /* TransformExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E4D50B1D841C6E00EC8815 /* TransformExampleView.swift */; };
|
||||
66AE19D71CC8C7EA00B78B5E /* SVGExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66AE19D61CC8C7EA00B78B5E /* SVGExampleViewController.swift */; };
|
||||
66AE19DB1CC8CB3C00B78B5E /* tiger.svg in Resources */ = {isa = PBXBuildFile; fileRef = 66AE19DA1CC8CB3C00B78B5E /* tiger.svg */; };
|
||||
B02E75F11C16104900D1971D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B02E75F01C16104900D1971D /* AppDelegate.swift */; };
|
||||
@ -69,6 +70,7 @@
|
||||
574EC4431CBB60AF0063F317 /* AnimationsExampleController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnimationsExampleController.swift; sourceTree = "<group>"; };
|
||||
575129B51CBD14AF00BD3C2E /* AnimationsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnimationsView.swift; sourceTree = "<group>"; };
|
||||
578791A01CEDCE8B008D85A1 /* tree.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = tree.svg; path = Example/Assets/SVG/tree.svg; sourceTree = "<group>"; };
|
||||
58E4D50B1D841C6E00EC8815 /* TransformExampleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransformExampleView.swift; sourceTree = "<group>"; };
|
||||
66AE19D61CC8C7EA00B78B5E /* SVGExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SVGExampleViewController.swift; path = SVG/SVGExampleViewController.swift; sourceTree = "<group>"; };
|
||||
66AE19DA1CC8CB3C00B78B5E /* tiger.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = tiger.svg; path = Example/Assets/SVG/tiger.svg; sourceTree = "<group>"; };
|
||||
B02E75ED1C16104900D1971D /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@ -135,6 +137,7 @@
|
||||
574EC4331CB7DE7F0063F317 /* Shapes */,
|
||||
574EC4351CB7DE7F0063F317 /* Text */,
|
||||
574EC4401CB7E2440063F317 /* MenuViewController.swift */,
|
||||
58E4D50B1D841C6E00EC8815 /* TransformExampleView.swift */,
|
||||
);
|
||||
path = Examples;
|
||||
sourceTree = "<group>";
|
||||
@ -424,6 +427,7 @@
|
||||
66AE19D71CC8C7EA00B78B5E /* SVGExampleViewController.swift in Sources */,
|
||||
24B291241D523F0B000498B3 /* ShapesEventsExampleView.swift in Sources */,
|
||||
B0A258851D50D81600829B35 /* SVGChartsView.swift in Sources */,
|
||||
58E4D50C1D841C6E00EC8815 /* TransformExampleView.swift in Sources */,
|
||||
24BE07041C6DF1F000B5882F /* BasePageViewController.swift in Sources */,
|
||||
574EC43A1CB7DE7F0063F317 /* DiagramExampleView.swift in Sources */,
|
||||
B02E75F11C16104900D1971D /* AppDelegate.swift in Sources */,
|
||||
|
@ -240,6 +240,24 @@
|
||||
</objects>
|
||||
<point key="canvasLocation" x="1339" y="470"/>
|
||||
</scene>
|
||||
<!--Transform-->
|
||||
<scene sceneID="rdc-fb-hVp">
|
||||
<objects>
|
||||
<viewController storyboardIdentifier="TransformExampleController" title="Transform" id="ETt-ZG-4Pm" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="Xny-4z-bkO"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="H90-y3-MSk"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="dvB-yS-FLM" customClass="TransformExampleView" customModule="Example" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="IZc-VS-62C" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="2006" y="470"/>
|
||||
</scene>
|
||||
<!--Model Listeners-->
|
||||
<scene sceneID="v8O-OB-49M">
|
||||
<objects>
|
||||
|
@ -9,6 +9,7 @@ class BasePageViewController: UIPageViewController {
|
||||
self.newMacawViewController("FirstPageViewController"),
|
||||
self.newMacawViewController("SecondPageViewController"),
|
||||
self.newMacawViewController("PathExampleController"),
|
||||
self.newMacawViewController("TransformExampleController"),
|
||||
self.newMacawViewController("FourthPageViewController"),
|
||||
self.newMacawViewController("AnimationsExampleController"),
|
||||
self.newMacawViewController("ModelListenersExampleController"),
|
||||
|
69
Example/Example/Examples/TransformExampleView.swift
Normal file
69
Example/Example/Examples/TransformExampleView.swift
Normal file
@ -0,0 +1,69 @@
|
||||
//
|
||||
// TransformExampleView.swift
|
||||
// Example
|
||||
//
|
||||
// Created by Yuri Strot on 9/10/16.
|
||||
// Copyright © 2016 Exyte. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
import UIKit
|
||||
import Macaw
|
||||
|
||||
class TransformExampleView: MacawView {
|
||||
|
||||
private static let transforms = [Transform.scale(sx: 2, sy: 2),
|
||||
Transform.move(dx: 100, dy: 30),
|
||||
Transform.rotate(angle: M_PI_4, x: 150, y: 80),
|
||||
Transform.rotate(angle: M_PI_4)]
|
||||
|
||||
private static let titles = ["Transform.scale(sx: 2, sy: 2)",
|
||||
"Transform.move(dx: 100, dy: 30)",
|
||||
"Transform.rotate(angle: M_PI_4, x: 150, y: 80)",
|
||||
"Transform.rotate(angle: M_PI_4)"]
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init(node: TransformExampleView.newScene(), coder: aDecoder)
|
||||
}
|
||||
|
||||
private static func newScene() -> Node {
|
||||
let shape = Shape(form: Rect(x: 0, y: 0, w: 50, h: 50), fill: Color.blue)
|
||||
let textes = Group(place: .move(dx: 50, dy: 275))
|
||||
for (i, item) in titles.enumerate() {
|
||||
let place = Transform.move(dx: 0, dy: Double(i * 25))
|
||||
textes.contents.append(Text(text: item, baseline: .bottom, place: place, opacity: 0))
|
||||
}
|
||||
var combines: [Transform] = [Transform.identity]
|
||||
for transform in transforms {
|
||||
combines.append(GeomUtils.concat(t1: transform, t2: combines.last!))
|
||||
}
|
||||
var state = 0
|
||||
_ = shape.onTap.subscribeNext { tap in
|
||||
if (state < textes.contents.count) {
|
||||
textes.contents[state].opacityVar.animate(from: 0.0, to: 1.0, during: 0.6)
|
||||
} else {
|
||||
for item in textes.contents {
|
||||
item.opacityVar.animate(from: 1.0, to: 0.0, during: 0.6)
|
||||
}
|
||||
}
|
||||
state = (state + 1) % 5;
|
||||
shape.placeVar.animate(to: combines[state], during: 0.6)
|
||||
}
|
||||
return Group(contents: [newAxes(), shape, textes], place: .move(dx: 10, dy: 30))
|
||||
}
|
||||
|
||||
private static func newAxes() -> Node {
|
||||
var items: [Node] = []
|
||||
let gray = Color(val: 0xF0F0F0)
|
||||
for i in 1...20 {
|
||||
let shift = Double(i) * 50.0
|
||||
items.append(Line(x1: -50, y1: shift, x2: 1000, y2: shift).stroke(fill: gray))
|
||||
items.append(Line(x1: shift, y1: -50, x2: shift, y2: 1000).stroke(fill: gray))
|
||||
}
|
||||
items.append(Line(x1: -10, y1: 0, x2: 1000, y2: 0).stroke())
|
||||
items.append(Line(x1: 0, y1: -10, x2: 0, y2: 1000).stroke())
|
||||
return Group(contents: items)
|
||||
}
|
||||
|
||||
}
|
@ -55,8 +55,8 @@ public extension AnimatableVariable {
|
||||
return TransformAnimation(animatedNode: node, valueFunc: desc.valueFunc, animationDuration: desc.duration, autostart: false)
|
||||
}
|
||||
|
||||
public func animate(from from: Transform, to: Transform, during: Double) {
|
||||
self.animate((from >> to).t(during))
|
||||
public func animate(from from: Transform? = nil, to: Transform, during: Double) {
|
||||
self.animate(((from ?? node!.place) >> to).t(during))
|
||||
}
|
||||
|
||||
public func animation(from from: Transform, to: Transform, during: Double) -> Animation {
|
||||
|
Loading…
Reference in New Issue
Block a user