-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.m
More file actions
84 lines (72 loc) · 2.99 KB
/
ViewController.m
File metadata and controls
84 lines (72 loc) · 2.99 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// ViewController.m
// ShapeAnimation_OSXDemo
//
// Created by Zhang Yungui on 15/3/9.
// Copyright (c) 2015 github.com/rhcad. All rights reserved.
//
#import "ViewController.h"
#import "ShapeAnimation.h"
@implementation ViewController
- (void)loadView {
[super loadView];
[self testMoveLines:self.shapeView];
}
- (void)testMoveLines:(SAShapeView *)view {
CGPathRef path = CGPathFromSVGPath(@"M120,70 C0,200 150,375 250,220 T500,220");
// Add a triangle with gradient fill
CAShapeLayer *la1 = [view addShapeLayer:CGPathFromSVGPath(@"M10,20L80,40 20,100Z")];
la1.gradient = [SAGradient gradient:@[(id)CGColorFromRGBA(0.5, 0.5, 0.9, 1.0),
(id)CGColorFromRGBA(0.9, 0.9, 0.3, 1.0)]];
// Move and rotate the triangle along the path
SAAnimationPair *a1 = [[la1 moveOnPathAnimation:path] setDuration:1.6];
SAAnimationPair *a2 = [la1.rotate360Degrees forever];
[[CAAnimationGroup group:@[a1, a2]].autoreverses.forever apply];
// Show the path with animated color
CAShapeLayer *guild = [view addShapeLayer:path];
[[guild strokeColorAnimation:SAColor.redColor.CGColor
to:SAColor.yellowColor.CGColor].autoreverses.forever apply];
// Rotate and move a picture along the path
CALayer *imageLayer = [view addImageLayer:CGPointMake(200, 200) named:@"airship.png"];
imageLayer.opacity = 0.7f;
[[[imageLayer moveOnPathAnimation:path autoRotate:YES] setBeginTime:1.0] applyWithDuration:4];
// Test hit-testing and dragging
view.didTap = ^(SAShapeView *view, CGPoint point) {
[view removeSelectionBorders];
CALayer *layer = [view hitTestLayer:point];
if (layer) {
[layer.tapAnimation apply:^{
[view addSelectionBorder:layer];
}];
}
};
__block NSArray *selectedLayers = nil;
view.didPan = ^(SAShapeView *view, SAPanRecognizer *sender) {
if (sender.state == SAGestureBegan) {
selectedLayers = view.selectedLayers;
[view removeSelectionBorders];
}
else if (sender.state == SAGestureChanged) {
CGPoint translation = [sender translationInView:view];
[sender setTranslation:CGPointZero inView:view];
for (CALayer *layer in selectedLayers) {
[CAAnimation suppressAnimation:^{
layer.position = SAPointAdd(layer.position, translation);
}];
}
}
else if (sender.state == SAGestureEnded) {
if ([selectedLayers containsObject:guild]) {
[[la1 moveOnPathAnimation:guild.pathToSuperlayer.CGPath]
.autoreverses.forever applyWithDuration:2];
}
[view addSelectionBorders:selectedLayers];
selectedLayers = nil;
}
};
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
// Update the view, if already loaded.
}
@end