Skip to content

Commit fc5397a

Browse files
committed
Add snowflake example.
1 parent 8909eb5 commit fc5397a

File tree

6 files changed

+152
-3
lines changed

6 files changed

+152
-3
lines changed

AdvancedGraphics/AdvancedGraphics.xcodeproj/project.pbxproj

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
B59C70DE1B7138570064D94F /* yosemite.jpg in Resources */ = {isa = PBXBuildFile; fileRef = B59C70DD1B7138570064D94F /* yosemite.jpg */; };
2020
B59C70E01B715DE10064D94F /* yosemite-optimized.png in Resources */ = {isa = PBXBuildFile; fileRef = B59C70DF1B715DE10064D94F /* yosemite-optimized.png */; };
2121
B59C70E31B754DC20064D94F /* ExpandingImageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B59C70E21B754DC20064D94F /* ExpandingImageViewController.m */; };
22+
B5C0EBCD1B75C9FE008B31E2 /* SnowViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B5C0EBCC1B75C9FE008B31E2 /* SnowViewController.m */; };
2223
/* End PBXBuildFile section */
2324

2425
/* Begin PBXFileReference section */
@@ -42,6 +43,8 @@
4243
B59C70DF1B715DE10064D94F /* yosemite-optimized.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "yosemite-optimized.png"; sourceTree = "<group>"; };
4344
B59C70E11B754DC20064D94F /* ExpandingImageViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExpandingImageViewController.h; sourceTree = "<group>"; };
4445
B59C70E21B754DC20064D94F /* ExpandingImageViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExpandingImageViewController.m; sourceTree = "<group>"; };
46+
B5C0EBCB1B75C9FE008B31E2 /* SnowViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SnowViewController.h; sourceTree = "<group>"; };
47+
B5C0EBCC1B75C9FE008B31E2 /* SnowViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SnowViewController.m; sourceTree = "<group>"; };
4548
/* End PBXFileReference section */
4649

4750
/* Begin PBXFrameworksBuildPhase section */
@@ -93,6 +96,8 @@
9396
B59C70E21B754DC20064D94F /* ExpandingImageViewController.m */,
9497
B50737531B75655A00C831B5 /* ImplicitAnimationViewController.h */,
9598
B50737541B75655A00C831B5 /* ImplicitAnimationViewController.m */,
99+
B5C0EBCB1B75C9FE008B31E2 /* SnowViewController.h */,
100+
B5C0EBCC1B75C9FE008B31E2 /* SnowViewController.m */,
96101
);
97102
path = AdvancedGraphics;
98103
sourceTree = "<group>";
@@ -182,6 +187,7 @@
182187
B59C70DC1B7133B80064D94F /* StutteringViewController.m in Sources */,
183188
B59C70D91B71311C0064D94F /* AnimationDemoViewController.m in Sources */,
184189
B59C70BF1B7129E80064D94F /* main.m in Sources */,
190+
B5C0EBCD1B75C9FE008B31E2 /* SnowViewController.m in Sources */,
185191
B59C70E31B754DC20064D94F /* ExpandingImageViewController.m in Sources */,
186192
B50737551B75655A00C831B5 /* ImplicitAnimationViewController.m in Sources */,
187193
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"filename" : "snowflake.png",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Loading

AdvancedGraphics/AdvancedGraphics/Base.lproj/Main.storyboard

+48-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,29 @@
5656
<segue destination="CKf-3b-yNF" kind="show" id="1xv-TZ-qoV"/>
5757
</connections>
5858
</tableViewCell>
59-
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="eUT-pX-xtb" rowHeight="64" style="IBUITableViewCellStyleDefault" id="FNx-1f-hio" userLabel="Expanding Image">
59+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="be8-tw-OXz" rowHeight="64" style="IBUITableViewCellStyleDefault" id="A0A-MT-o9A" userLabel="Snow Fall">
6060
<rect key="frame" x="0.0" y="192" width="600" height="64"/>
6161
<autoresizingMask key="autoresizingMask"/>
62+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="A0A-MT-o9A" id="5Yz-vC-uDk">
63+
<rect key="frame" x="0.0" y="0.0" width="600" height="63.5"/>
64+
<autoresizingMask key="autoresizingMask"/>
65+
<subviews>
66+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Snow Fall" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="be8-tw-OXz">
67+
<rect key="frame" x="15" y="0.0" width="570" height="63.5"/>
68+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
69+
<fontDescription key="fontDescription" type="system" pointSize="16"/>
70+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
71+
<nil key="highlightedColor"/>
72+
</label>
73+
</subviews>
74+
</tableViewCellContentView>
75+
<connections>
76+
<segue destination="7VV-RR-zDi" kind="show" id="Wbh-SV-RbW"/>
77+
</connections>
78+
</tableViewCell>
79+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="eUT-pX-xtb" rowHeight="64" style="IBUITableViewCellStyleDefault" id="FNx-1f-hio" userLabel="Expanding Image">
80+
<rect key="frame" x="0.0" y="256" width="600" height="64"/>
81+
<autoresizingMask key="autoresizingMask"/>
6282
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="FNx-1f-hio" id="iXt-v8-gIK">
6383
<rect key="frame" x="0.0" y="0.0" width="600" height="63.5"/>
6484
<autoresizingMask key="autoresizingMask"/>
@@ -77,7 +97,7 @@
7797
</connections>
7898
</tableViewCell>
7999
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="Gsq-uu-njt" rowHeight="64" style="IBUITableViewCellStyleDefault" id="03p-to-5Uk" userLabel="Stuttering Table View">
80-
<rect key="frame" x="0.0" y="256" width="600" height="64"/>
100+
<rect key="frame" x="0.0" y="320" width="600" height="64"/>
81101
<autoresizingMask key="autoresizingMask"/>
82102
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="03p-to-5Uk" id="ZVs-fR-AOL">
83103
<rect key="frame" x="0.0" y="0.0" width="600" height="63.5"/>
@@ -110,6 +130,31 @@
110130
</objects>
111131
<point key="canvasLocation" x="1175" y="616"/>
112132
</scene>
133+
<!--Snow Fall-->
134+
<scene sceneID="s3v-q3-tvz">
135+
<objects>
136+
<viewController id="7VV-RR-zDi" customClass="SnowViewController" sceneMemberID="viewController">
137+
<layoutGuides>
138+
<viewControllerLayoutGuide type="top" id="XNE-F9-nak"/>
139+
<viewControllerLayoutGuide type="bottom" id="GCI-jt-ue7"/>
140+
</layoutGuides>
141+
<view key="view" contentMode="scaleToFill" id="zNW-wP-tOm">
142+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
143+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
144+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
145+
</view>
146+
<navigationItem key="navigationItem" title="Snow Fall" id="G8c-w9-xlw">
147+
<barButtonItem key="rightBarButtonItem" title="Start" id="W02-DY-KIa">
148+
<connections>
149+
<action selector="didTapStart:" destination="7VV-RR-zDi" id="NPh-Zm-d8p"/>
150+
</connections>
151+
</barButtonItem>
152+
</navigationItem>
153+
</viewController>
154+
<placeholder placeholderIdentifier="IBFirstResponder" id="jFM-5G-Ro0" userLabel="First Responder" sceneMemberID="firstResponder"/>
155+
</objects>
156+
<point key="canvasLocation" x="2145" y="824"/>
157+
</scene>
113158
<!--Implicit Animation-->
114159
<scene sceneID="Iuk-gU-4nU">
115160
<objects>
@@ -395,7 +440,7 @@
395440
</viewController>
396441
<placeholder placeholderIdentifier="IBFirstResponder" id="DfV-wS-hOK" userLabel="First Responder" sceneMemberID="firstResponder"/>
397442
</objects>
398-
<point key="canvasLocation" x="2751" y="1547"/>
443+
<point key="canvasLocation" x="1991" y="2211"/>
399444
</scene>
400445
<!--Navigation Controller-->
401446
<scene sceneID="Tkx-PO-Jbb">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// SnowViewController.h
3+
// AdvancedGraphics
4+
//
5+
// Created by Benjamin Sandofsky on 8/7/15.
6+
// Copyright © 2015 Chroma Noir LLC. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface SnowViewController : UIViewController
12+
13+
@end
14+
15+
@interface SnowLayer : CALayer
16+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// SnowViewController.m
3+
// AdvancedGraphics
4+
//
5+
// Created by Benjamin Sandofsky on 8/7/15.
6+
// Copyright © 2015 Chroma Noir LLC. All rights reserved.
7+
//
8+
9+
#import "SnowViewController.h"
10+
11+
#define SNOW_COUNT 20
12+
13+
@interface SnowViewController ()
14+
@property (nonatomic, strong) NSMutableArray<SnowLayer *> *snowQueue;
15+
@end
16+
17+
@implementation SnowViewController
18+
19+
- (void)viewDidLoad
20+
{
21+
[super viewDidLoad];
22+
NSMutableArray<SnowLayer *> *array = [NSMutableArray array];
23+
UIImage *snowFlakeImage = [UIImage imageNamed:@"snowflake"];
24+
for (int i = 0; i < SNOW_COUNT; i++){
25+
SnowLayer *snow = [[SnowLayer alloc] init];
26+
snow.contents = (id)snowFlakeImage.CGImage;
27+
snow.frame = CGRectMake(0, -40, 40, 40);
28+
[self.view.layer addSublayer:snow];
29+
[array addObject:snow];
30+
}
31+
self.snowQueue = array;
32+
}
33+
34+
- (IBAction)didTapStart:(UIBarButtonItem *)sender {
35+
[CATransaction begin];
36+
[CATransaction setAnimationDuration:2.0];
37+
CGFloat offset = 0.0;
38+
for (SnowLayer *snow in self.snowQueue) {
39+
CABasicAnimation *animation = [CABasicAnimation animation];
40+
CGFloat x = (CGFloat)arc4random() / (CGFloat)UINT32_MAX * self.view.layer.bounds.size.width;
41+
CGPoint p = CGPointMake(x, -20.0);
42+
animation.fromValue = [NSValue valueWithCGPoint:p];
43+
animation.keyPath = @"position";
44+
p.y = self.view.frame.size.height + 20.0;
45+
animation.toValue = [NSValue valueWithCGPoint:p];
46+
CGFloat randomOffset = (CGFloat)arc4random() / (CGFloat)UINT32_MAX;
47+
offset += 0.5 + randomOffset / 2.0;
48+
animation.beginTime = CACurrentMediaTime() + offset;
49+
animation.repeatCount = 1000;
50+
[snow addAnimation:animation forKey:@"snowFall"];
51+
NSLog(@"Snowed: %f", x);
52+
}
53+
54+
[CATransaction commit];
55+
}
56+
57+
@end
58+
59+
@implementation SnowLayer
60+
61+
@end

0 commit comments

Comments
 (0)