Skip to content
This repository has been archived by the owner on Aug 10, 2019. It is now read-only.

Commit

Permalink
better animation and vibration for invalid entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan Kool committed Mar 18, 2011
1 parent 361e269 commit a6c047f
Show file tree
Hide file tree
Showing 5 changed files with 562 additions and 604 deletions.
5 changes: 0 additions & 5 deletions KVPasscodeViewController.h
Expand Up @@ -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;
Expand Down
31 changes: 28 additions & 3 deletions KVPasscodeViewController.m
Expand Up @@ -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

Expand Down Expand Up @@ -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:)];
Expand All @@ -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:)];
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions PasscodeSample/PasscodeSample.xcodeproj/project.pbxproj
Expand Up @@ -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 */
Expand All @@ -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 */,
Expand Down Expand Up @@ -80,6 +83,7 @@
C79F70E813325C64007B9A22 /* Frameworks */ = {
isa = PBXGroup;
children = (
C79F711113338C8F007B9A22 /* AudioToolbox.framework */,
C79F710E1332670E007B9A22 /* QuartzCore.framework */,
C79F70E913325C64007B9A22 /* UIKit.framework */,
C79F70EB13325C64007B9A22 /* Foundation.framework */,
Expand Down

0 comments on commit a6c047f

Please sign in to comment.