Skip to content
Browse files

better animation and vibration for invalid entry

  • Loading branch information...
1 parent 361e269 commit a6c047fc73aa5b04388df91c61f58b3e1db7b55c Johan Kool committed Mar 18, 2011
View
5 KVPasscodeViewController.h
@@ -28,11 +28,6 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
-//
-// Known issues:
-// - KVPasscodeAnimationStyleConfirm animation not quite perfect (bullets visible in incoming field)
-//
-
#import <UIKit/UIKit.h>
@class KVPasscodeViewController;
View
31 KVPasscodeViewController.m
@@ -31,10 +31,13 @@
#import "KVPasscodeViewController.h"
#import <QuartzCore/QuartzCore.h>
+#import <AudioToolbox/AudioServices.h>
@interface KVPasscodeViewController ()
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;
+- (void)internalResetWithAnimation:(NSNumber *)animationStyleNumber;
+- (void)notifyDelegate:(NSString *)passcode;
@end
@@ -120,10 +123,15 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-- (void)resetWithAnimation:(KVPasscodeAnimationStyle)animationStyle {
+- (void)internalResetWithAnimation:(NSNumber *)animationStyleNumber {
+ KVPasscodeAnimationStyle animationStyle = [animationStyleNumber intValue];
switch (animationStyle) {
case KVPasscodeAnimationStyleInvalid:
;
+
+ // Vibrate to indicate error
+ AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
+
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
[animation setDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];
@@ -138,6 +146,12 @@ - (void)resetWithAnimation:(KVPasscodeAnimationStyle)animationStyle {
break;
case KVPasscodeAnimationStyleConfirm:
;
+
+ self.bulletField0.text = nil;
+ self.bulletField1.text = nil;
+ self.bulletField2.text = nil;
+ self.bulletField3.text = nil;
+
CATransition *transition = [CATransition animation];
[transition setDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];
@@ -160,6 +174,16 @@ - (void)resetWithAnimation:(KVPasscodeAnimationStyle)animationStyle {
}
}
+- (void)resetWithAnimation:(KVPasscodeAnimationStyle)animationStyle {
+ // Do the animation a little later, for better animatio
+ [self performSelector:@selector(internalResetWithAnimation:) withObject:[NSNumber numberWithInt:animationStyle] afterDelay:0];
+}
+
+- (void)notifyDelegate:(NSString *)passcode {
+ [self.delegate passcodeController:self passcodeEntered:passcode];
+ fakeField.text = @"";
+}
+
#pragma mark - CAAnimationDelegate
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
self.bulletField0.text = nil;
@@ -206,8 +230,9 @@ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRang
self.bulletField2.text = @"*";
self.bulletField3.text = @"*";
- [self.delegate passcodeController:self passcodeEntered:passcode];
- textField.text = @"";
+ // Notify delegate a little later so we have a change to show the 4th bullet
+ [self performSelector:@selector(notifyDelegate:) withObject:passcode afterDelay:0];
+
return NO;
break;
View
4 PasscodeSample/PasscodeSample.xcodeproj/project.pbxproj
@@ -19,6 +19,7 @@
C79F710C13325C73007B9A22 /* KVPasscodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C79F710A13325C73007B9A22 /* KVPasscodeViewController.m */; };
C79F710D13325C73007B9A22 /* KVPasscodeViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C79F710B13325C73007B9A22 /* KVPasscodeViewController.xib */; };
C79F710F1332670E007B9A22 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C79F710E1332670E007B9A22 /* QuartzCore.framework */; };
+ C79F711213338C8F007B9A22 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C79F711113338C8F007B9A22 /* AudioToolbox.framework */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -40,13 +41,15 @@
C79F710A13325C73007B9A22 /* KVPasscodeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = KVPasscodeViewController.m; path = ../KVPasscodeViewController.m; sourceTree = "<group>"; };
C79F710B13325C73007B9A22 /* KVPasscodeViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = KVPasscodeViewController.xib; path = ../KVPasscodeViewController.xib; sourceTree = "<group>"; };
C79F710E1332670E007B9A22 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
+ C79F711113338C8F007B9A22 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
C79F70E213325C64007B9A22 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ C79F711213338C8F007B9A22 /* AudioToolbox.framework in Frameworks */,
C79F710F1332670E007B9A22 /* QuartzCore.framework in Frameworks */,
C79F70EA13325C64007B9A22 /* UIKit.framework in Frameworks */,
C79F70EC13325C64007B9A22 /* Foundation.framework in Frameworks */,
@@ -80,6 +83,7 @@
C79F70E813325C64007B9A22 /* Frameworks */ = {
isa = PBXGroup;
children = (
+ C79F711113338C8F007B9A22 /* AudioToolbox.framework */,
C79F710E1332670E007B9A22 /* QuartzCore.framework */,
C79F70E913325C64007B9A22 /* UIKit.framework */,
C79F70EB13325C64007B9A22 /* Foundation.framework */,
View
1,124 ...xcodeproj/project.xcworkspace/xcuserdata/jkool.xcuserdatad/UserInterfaceState.xcuserstate
529 additions, 595 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
2 README.mdown
@@ -5,7 +5,7 @@ A view controller that lets you enter 4 digit pass codes. It supports animations
USAGE
-----
-Your app needs to link against the QuartzCore framework.
+Your app needs to link against the QuartzCore framework and the AudioToolbox framework.
SAMPLE
------

0 comments on commit a6c047f

Please sign in to comment.
Something went wrong with that request. Please try again.