Skip to content

Commit

Permalink
Merge pull request #45 from natan/natan/displaylink
Browse files Browse the repository at this point in the history
Replace NSTimer-backed update mechanism with CADisplayLink for more reliable updates
  • Loading branch information
dataxpress committed Jan 30, 2016
2 parents c108038 + 59ac843 commit 069364c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
9 changes: 8 additions & 1 deletion CountingTestProject.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
33EFDA461C56C4C40084A36A /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33EFDA451C56C4C40084A36A /* QuartzCore.framework */; };
4C5DC2A416C576E30043204D /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C5DC2A316C576E30043204D /* UIKit.framework */; };
4C5DC2A616C576E30043204D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C5DC2A516C576E30043204D /* Foundation.framework */; };
4C5DC2A816C576E30043204D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C5DC2A716C576E30043204D /* CoreGraphics.framework */; };
Expand All @@ -22,6 +23,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
33EFDA451C56C4C40084A36A /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
4C5DC2A016C576E30043204D /* CountingTestProject.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CountingTestProject.app; sourceTree = BUILT_PRODUCTS_DIR; };
4C5DC2A316C576E30043204D /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
4C5DC2A516C576E30043204D /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand All @@ -47,6 +49,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
33EFDA461C56C4C40084A36A /* QuartzCore.framework in Frameworks */,
4C5DC2A416C576E30043204D /* UIKit.framework in Frameworks */,
4C5DC2A616C576E30043204D /* Foundation.framework in Frameworks */,
4C5DC2A816C576E30043204D /* CoreGraphics.framework in Frameworks */,
Expand Down Expand Up @@ -76,6 +79,7 @@
4C5DC2A216C576E30043204D /* Frameworks */ = {
isa = PBXGroup;
children = (
33EFDA451C56C4C40084A36A /* QuartzCore.framework */,
4C5DC2A316C576E30043204D /* UIKit.framework */,
4C5DC2A516C576E30043204D /* Foundation.framework */,
4C5DC2A716C576E30043204D /* CoreGraphics.framework */,
Expand Down Expand Up @@ -139,7 +143,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = CTP;
LastUpgradeCheck = 0460;
LastUpgradeCheck = 0720;
ORGANIZATIONNAME = "Tim Gostony";
};
buildConfigurationList = 4C5DC29B16C576E30043204D /* Build configuration list for PBXProject "CountingTestProject" */;
Expand Down Expand Up @@ -222,6 +226,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -271,6 +276,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "CountingTestProject/CountingTestProject-Prefix.pch";
INFOPLIST_FILE = "CountingTestProject/CountingTestProject-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.timgostony.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -283,6 +289,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "CountingTestProject/CountingTestProject-Prefix.pch";
INFOPLIST_FILE = "CountingTestProject/CountingTestProject-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.timgostony.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand Down
2 changes: 1 addition & 1 deletion CountingTestProject/CountingTestProject-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.timgostony.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
11 changes: 7 additions & 4 deletions UICountingLabel.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#import <QuartzCore/QuartzCore.h>

#import "UICountingLabel.h"

#if !__has_feature(objc_arc)
Expand Down Expand Up @@ -86,7 +88,7 @@ @interface UICountingLabel ()
@property NSTimeInterval totalTime;
@property CGFloat easingRate;

@property (nonatomic, weak) NSTimer *timer;
@property (nonatomic, strong) CADisplayLink *timer;
@property (nonatomic, strong) id<UILabelCounter> counter;

@end
Expand Down Expand Up @@ -142,9 +144,10 @@ -(void)countFrom:(CGFloat)startValue to:(CGFloat)endValue withDuration:(NSTimeIn
break;
}

NSTimer *timer = [NSTimer timerWithTimeInterval:(1.0f/30.0f) target:self selector:@selector(updateValue:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:UITrackingRunLoopMode];
CADisplayLink *timer = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateValue:)];
timer.frameInterval = 2;
[timer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[timer addToRunLoop:[NSRunLoop mainRunLoop] forMode:UITrackingRunLoopMode];
self.timer = timer;
}

Expand Down

0 comments on commit 069364c

Please sign in to comment.