Skip to content

Commit

Permalink
Add snowflake example.
Browse files Browse the repository at this point in the history
  • Loading branch information
sandofsky committed Aug 10, 2015
1 parent 8909eb5 commit fc5397a
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 3 deletions.
6 changes: 6 additions & 0 deletions AdvancedGraphics/AdvancedGraphics.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
B59C70DE1B7138570064D94F /* yosemite.jpg in Resources */ = {isa = PBXBuildFile; fileRef = B59C70DD1B7138570064D94F /* yosemite.jpg */; };
B59C70E01B715DE10064D94F /* yosemite-optimized.png in Resources */ = {isa = PBXBuildFile; fileRef = B59C70DF1B715DE10064D94F /* yosemite-optimized.png */; };
B59C70E31B754DC20064D94F /* ExpandingImageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B59C70E21B754DC20064D94F /* ExpandingImageViewController.m */; };
B5C0EBCD1B75C9FE008B31E2 /* SnowViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B5C0EBCC1B75C9FE008B31E2 /* SnowViewController.m */; };
/* End PBXBuildFile section */

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

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -93,6 +96,8 @@
B59C70E21B754DC20064D94F /* ExpandingImageViewController.m */,
B50737531B75655A00C831B5 /* ImplicitAnimationViewController.h */,
B50737541B75655A00C831B5 /* ImplicitAnimationViewController.m */,
B5C0EBCB1B75C9FE008B31E2 /* SnowViewController.h */,
B5C0EBCC1B75C9FE008B31E2 /* SnowViewController.m */,
);
path = AdvancedGraphics;
sourceTree = "<group>";
Expand Down Expand Up @@ -182,6 +187,7 @@
B59C70DC1B7133B80064D94F /* StutteringViewController.m in Sources */,
B59C70D91B71311C0064D94F /* AnimationDemoViewController.m in Sources */,
B59C70BF1B7129E80064D94F /* main.m in Sources */,
B5C0EBCD1B75C9FE008B31E2 /* SnowViewController.m in Sources */,
B59C70E31B754DC20064D94F /* ExpandingImageViewController.m in Sources */,
B50737551B75655A00C831B5 /* ImplicitAnimationViewController.m in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "snowflake.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 48 additions & 3 deletions AdvancedGraphics/AdvancedGraphics/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,29 @@
<segue destination="CKf-3b-yNF" kind="show" id="1xv-TZ-qoV"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="eUT-pX-xtb" rowHeight="64" style="IBUITableViewCellStyleDefault" id="FNx-1f-hio" userLabel="Expanding Image">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="be8-tw-OXz" rowHeight="64" style="IBUITableViewCellStyleDefault" id="A0A-MT-o9A" userLabel="Snow Fall">
<rect key="frame" x="0.0" y="192" width="600" height="64"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="A0A-MT-o9A" id="5Yz-vC-uDk">
<rect key="frame" x="0.0" y="0.0" width="600" height="63.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Snow Fall" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="be8-tw-OXz">
<rect key="frame" x="15" y="0.0" width="570" height="63.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="7VV-RR-zDi" kind="show" id="Wbh-SV-RbW"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="eUT-pX-xtb" rowHeight="64" style="IBUITableViewCellStyleDefault" id="FNx-1f-hio" userLabel="Expanding Image">
<rect key="frame" x="0.0" y="256" width="600" height="64"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="FNx-1f-hio" id="iXt-v8-gIK">
<rect key="frame" x="0.0" y="0.0" width="600" height="63.5"/>
<autoresizingMask key="autoresizingMask"/>
Expand All @@ -77,7 +97,7 @@
</connections>
</tableViewCell>
<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">
<rect key="frame" x="0.0" y="256" width="600" height="64"/>
<rect key="frame" x="0.0" y="320" width="600" height="64"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="03p-to-5Uk" id="ZVs-fR-AOL">
<rect key="frame" x="0.0" y="0.0" width="600" height="63.5"/>
Expand Down Expand Up @@ -110,6 +130,31 @@
</objects>
<point key="canvasLocation" x="1175" y="616"/>
</scene>
<!--Snow Fall-->
<scene sceneID="s3v-q3-tvz">
<objects>
<viewController id="7VV-RR-zDi" customClass="SnowViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="XNE-F9-nak"/>
<viewControllerLayoutGuide type="bottom" id="GCI-jt-ue7"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="zNW-wP-tOm">
<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>
<navigationItem key="navigationItem" title="Snow Fall" id="G8c-w9-xlw">
<barButtonItem key="rightBarButtonItem" title="Start" id="W02-DY-KIa">
<connections>
<action selector="didTapStart:" destination="7VV-RR-zDi" id="NPh-Zm-d8p"/>
</connections>
</barButtonItem>
</navigationItem>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="jFM-5G-Ro0" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2145" y="824"/>
</scene>
<!--Implicit Animation-->
<scene sceneID="Iuk-gU-4nU">
<objects>
Expand Down Expand Up @@ -395,7 +440,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="DfV-wS-hOK" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2751" y="1547"/>
<point key="canvasLocation" x="1991" y="2211"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="Tkx-PO-Jbb">
Expand Down
16 changes: 16 additions & 0 deletions AdvancedGraphics/AdvancedGraphics/SnowViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// SnowViewController.h
// AdvancedGraphics
//
// Created by Benjamin Sandofsky on 8/7/15.
// Copyright © 2015 Chroma Noir LLC. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface SnowViewController : UIViewController

@end

@interface SnowLayer : CALayer
@end
61 changes: 61 additions & 0 deletions AdvancedGraphics/AdvancedGraphics/SnowViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// SnowViewController.m
// AdvancedGraphics
//
// Created by Benjamin Sandofsky on 8/7/15.
// Copyright © 2015 Chroma Noir LLC. All rights reserved.
//

#import "SnowViewController.h"

#define SNOW_COUNT 20

@interface SnowViewController ()
@property (nonatomic, strong) NSMutableArray<SnowLayer *> *snowQueue;
@end

@implementation SnowViewController

- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray<SnowLayer *> *array = [NSMutableArray array];
UIImage *snowFlakeImage = [UIImage imageNamed:@"snowflake"];
for (int i = 0; i < SNOW_COUNT; i++){
SnowLayer *snow = [[SnowLayer alloc] init];
snow.contents = (id)snowFlakeImage.CGImage;
snow.frame = CGRectMake(0, -40, 40, 40);
[self.view.layer addSublayer:snow];
[array addObject:snow];
}
self.snowQueue = array;
}

- (IBAction)didTapStart:(UIBarButtonItem *)sender {
[CATransaction begin];
[CATransaction setAnimationDuration:2.0];
CGFloat offset = 0.0;
for (SnowLayer *snow in self.snowQueue) {
CABasicAnimation *animation = [CABasicAnimation animation];
CGFloat x = (CGFloat)arc4random() / (CGFloat)UINT32_MAX * self.view.layer.bounds.size.width;
CGPoint p = CGPointMake(x, -20.0);
animation.fromValue = [NSValue valueWithCGPoint:p];
animation.keyPath = @"position";
p.y = self.view.frame.size.height + 20.0;
animation.toValue = [NSValue valueWithCGPoint:p];
CGFloat randomOffset = (CGFloat)arc4random() / (CGFloat)UINT32_MAX;
offset += 0.5 + randomOffset / 2.0;
animation.beginTime = CACurrentMediaTime() + offset;
animation.repeatCount = 1000;
[snow addAnimation:animation forKey:@"snowFall"];
NSLog(@"Snowed: %f", x);
}

[CATransaction commit];
}

@end

@implementation SnowLayer

@end

0 comments on commit fc5397a

Please sign in to comment.