Skip to content

Commit

Permalink
Add layer actions demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
sandofsky committed Aug 7, 2015
1 parent c008669 commit 8909eb5
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 5 deletions.
6 changes: 6 additions & 0 deletions AdvancedGraphics/AdvancedGraphics.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
B50737551B75655A00C831B5 /* ImplicitAnimationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B50737541B75655A00C831B5 /* ImplicitAnimationViewController.m */; };
B59C70BF1B7129E80064D94F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B59C70BE1B7129E80064D94F /* main.m */; };
B59C70C21B7129E80064D94F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B59C70C11B7129E80064D94F /* AppDelegate.m */; };
B59C70C81B7129E80064D94F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B59C70C61B7129E80064D94F /* Main.storyboard */; };
Expand All @@ -21,6 +22,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
B50737531B75655A00C831B5 /* ImplicitAnimationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImplicitAnimationViewController.h; sourceTree = "<group>"; };
B50737541B75655A00C831B5 /* ImplicitAnimationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImplicitAnimationViewController.m; sourceTree = "<group>"; };
B59C70BA1B7129E80064D94F /* AdvancedGraphics.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AdvancedGraphics.app; sourceTree = BUILT_PRODUCTS_DIR; };
B59C70BE1B7129E80064D94F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
B59C70C01B7129E80064D94F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -88,6 +91,8 @@
B59C70DB1B7133B80064D94F /* StutteringViewController.m */,
B59C70E11B754DC20064D94F /* ExpandingImageViewController.h */,
B59C70E21B754DC20064D94F /* ExpandingImageViewController.m */,
B50737531B75655A00C831B5 /* ImplicitAnimationViewController.h */,
B50737541B75655A00C831B5 /* ImplicitAnimationViewController.m */,
);
path = AdvancedGraphics;
sourceTree = "<group>";
Expand Down Expand Up @@ -178,6 +183,7 @@
B59C70D91B71311C0064D94F /* AnimationDemoViewController.m in Sources */,
B59C70BF1B7129E80064D94F /* main.m in Sources */,
B59C70E31B754DC20064D94F /* ExpandingImageViewController.m in Sources */,
B50737551B75655A00C831B5 /* ImplicitAnimationViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
73 changes: 68 additions & 5 deletions AdvancedGraphics/AdvancedGraphics/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,29 @@
<segue destination="boF-Rd-kNh" kind="show" id="nZ0-fG-4ny"/>
</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="Xvc-Tq-z6c" rowHeight="64" style="IBUITableViewCellStyleDefault" id="4UM-Ks-huQ" userLabel="Implicit Animation">
<rect key="frame" x="0.0" y="128" width="600" height="64"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="4UM-Ks-huQ" id="AfZ-th-ol0">
<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="Implicit Animation" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Xvc-Tq-z6c">
<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="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">
<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="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 @@ -57,7 +77,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="192" width="600" height="64"/>
<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="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 @@ -90,6 +110,49 @@
</objects>
<point key="canvasLocation" x="1175" y="616"/>
</scene>
<!--Implicit Animation-->
<scene sceneID="Iuk-gU-4nU">
<objects>
<viewController id="CKf-3b-yNF" customClass="ImplicitAnimationViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="CYu-Cj-mg9"/>
<viewControllerLayoutGuide type="bottom" id="HTg-dZ-wfd"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="d21-Va-ycF">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Fgd-fG-SJo" customClass="MyCustomView">
<rect key="frame" x="280" y="279.5" width="40" height="40"/>
<color key="backgroundColor" red="0.92941176469999998" green="0.15686274510000001" blue="0.25490196079999999" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="width" constant="40" id="NHX-AT-k9x"/>
<constraint firstAttribute="height" constant="40" id="ctl-Wf-Oei"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="Fgd-fG-SJo" firstAttribute="centerY" secondItem="d21-Va-ycF" secondAttribute="centerY" id="HhI-Cm-QfD"/>
<constraint firstItem="Fgd-fG-SJo" firstAttribute="centerX" secondItem="d21-Va-ycF" secondAttribute="centerX" id="O2L-3w-mDi"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Implicit Animation" id="kCh-De-2VE">
<barButtonItem key="rightBarButtonItem" title="Go" id="m53-fV-g1U">
<connections>
<action selector="didTapGo:" destination="CKf-3b-yNF" id="T5v-ca-gog"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="animatedView" destination="Fgd-fG-SJo" id="9AW-F6-SCS"/>
<outlet property="centerConstraint" destination="O2L-3w-mDi" id="F9j-to-V2d"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="OZA-p7-RN5" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1999" y="-101"/>
</scene>
<!--Expanding-->
<scene sceneID="fQ1-aN-FXk">
<objects>
Expand Down Expand Up @@ -221,7 +284,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="1z7-mw-Hqz" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2189" y="-128"/>
<point key="canvasLocation" x="2685" y="-58"/>
</scene>
<!--Stuttering View Controller-->
<scene sceneID="5C9-DY-YfZ">
Expand Down Expand Up @@ -277,7 +340,7 @@
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Mkx-1E-s4L" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2175" y="664"/>
<point key="canvasLocation" x="2813" y="634"/>
</scene>
<!--Layer Walkthrough View Controller-->
<scene sceneID="Sk5-1T-Ii9">
Expand Down Expand Up @@ -332,7 +395,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="DfV-wS-hOK" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1687" y="1409"/>
<point key="canvasLocation" x="2751" y="1547"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="Tkx-PO-Jbb">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// ImplicitAnimationViewController.h
// AdvancedGraphics
//
// Created by Ben Sandofsky on 8/7/15.
// Copyright © 2015 Chroma Noir LLC. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ImplicitAnimationViewController : UIViewController
@end

@interface MyCustomView : UIView
@property (nonatomic, assign) BOOL isGoing;
@end

@interface MyCustomLayer:CALayer
@property (nonatomic, assign) BOOL isGoing;
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// ImplicitAnimationViewController.m
// AdvancedGraphics
//
// Created by Ben Sandofsky on 8/7/15.
// Copyright © 2015 Chroma Noir LLC. All rights reserved.
//

#import "ImplicitAnimationViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface ImplicitAnimationViewController ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *centerConstraint;
@property (weak, nonatomic) IBOutlet MyCustomView *animatedView;

@end

@implementation ImplicitAnimationViewController
- (IBAction)didTapGo:(UIBarButtonItem *)sender {
self.centerConstraint.constant = 100;
[UIView animateWithDuration:0.35 animations:^{
[self.view layoutIfNeeded];
self.animatedView.isGoing = true;
}];
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.centerConstraint.constant = -100;
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}

- (nullable id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event
{
return nil;
}

@end

@implementation MyCustomView

+ (Class)layerClass {
return [MyCustomLayer class];
}

- (nullable id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event
{
id action = [super actionForLayer:layer forKey:event];
NSLog(@"key: %@, Action: %@", event, action);
return action;
}

- (void)setIsGoing:(BOOL)isGoing
{
MyCustomLayer *l = (MyCustomLayer *)self.layer;
l.isGoing = isGoing;
}

- (BOOL)isGoing
{
return [(MyCustomLayer *)self.layer isGoing];
}

@end

@implementation MyCustomLayer
- (id)init
{
self = [super init];
if (self){
[self _updateColor];
}
return self;
}
- (void)setIsGoing:(BOOL)isGoing
{
_isGoing = isGoing;
[self _updateColor];
}

- (void)_updateColor
{
self.backgroundColor = _isGoing ? [UIColor greenColor].CGColor : [UIColor redColor].CGColor;
}

@end

0 comments on commit 8909eb5

Please sign in to comment.