Permalink
Browse files

Adding a disabled slide to unlock mode that vibrates the phone when i…

…ts in that mode.
  • Loading branch information...
1 parent cf0a1df commit 85116f4c528422952105a07138dd57f61ee4fa1d @devinross committed Feb 25, 2014
@@ -57,6 +57,8 @@ - (void) loadView{
self.unlockView = [[TKSlideToUnlockView alloc] initWithFrame:CGRectMake((w-width)/2.0f, 330, width, 40)];
self.unlockView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
+
+
[self.view addSubview:self.unlockView];
[self.unlockView addTarget:self action:@selector(didUnlockView:) forControlEvents:UIControlEventValueChanged];
@@ -84,6 +86,9 @@ - (void) viewDidLoad{
}
+ self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Disable", @"Disable") style:UIBarButtonItemStylePlain target:self action:@selector(switchMode:)];
+
+
}
- (void) viewWillAppear:(BOOL)animated{
@@ -101,4 +106,10 @@ - (void) reset{
}
+- (void) switchMode:(id)sender{
+
+
+ self.unlockView.mode = self.unlockView.mode == TKSlideToUnlockViewModeDisabled ? TKSlideToUnlockViewModeNormal : TKSlideToUnlockViewModeDisabled;
+}
+
@end
@@ -30,16 +30,24 @@
*/
@import UIKit;
-
+@import AudioToolbox;
@class TKShimmerLabel;
+typedef enum {
+ TKSlideToUnlockViewModeNormal = 0,
+ TKSlideToUnlockViewModeDisabled = 1
+} TKSlideToUnlockViewMode;
+
+
@interface TKSlideToUnlockView : UIControl <UIScrollViewDelegate>
@property (nonatomic,strong) TKShimmerLabel *textLabel;
@property (nonatomic,strong) UIScrollView *scrollView;
@property (nonatomic,strong) UIImageView *backgroundView;
@property (nonatomic,readonly) BOOL isUnlocked;
+@property (nonatomic,assign) TKSlideToUnlockViewMode mode;
+
- (void) resetSlider:(BOOL)animated;
@end
@@ -68,6 +68,10 @@ - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
#define SLIDER_VIEW_WIDTH 82.0f
#define FADE_TEXT_OVER_LENGTH 50.0f
+@interface TKSlideToUnlockView ()
+@property (nonatomic,strong) UIColor *stashedBackgroundColor;
+@end
+
@implementation TKSlideToUnlockView
#pragma mark Init & Friends
@@ -90,23 +94,20 @@ - (id) initWithCoder:(NSCoder *)aDecoder{
-
-
- (void) awakeFromNib{
[self _setupView];
}
- (void) _setupView{
-
+ self.mode = TKSlideToUnlockViewModeNormal;
self.backgroundView = [UIImageView imageViewWithFrame:self.bounds];
self.backgroundView.layer.cornerRadius = 5;
self.backgroundView.clipsToBounds = YES;
[self addSubview:self.backgroundView];
-
self.scrollView = [[CustomScrollView alloc] initWithFrame:self.bounds];
self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.scrollView.frame)*2, 0);
- self.scrollView.backgroundColor = [UIColor colorWithRed:233/255.0f green:52/255.0f blue:41/255.0f alpha:0.7];
+ self.scrollView.backgroundColor = [UIColor colorWithRed:76/255. green:217/255. blue:100/255. alpha:0.7];
self.scrollView.layer.cornerRadius = 5;
self.scrollView.pagingEnabled = YES;
self.scrollView.bounces = NO;
@@ -117,7 +118,6 @@ - (void) _setupView{
self.scrollView.contentOffset = CGPointMake(CGRectGetWidth(self.scrollView.frame), 0);
-
UIImage *arrow = [UIImage imageNamedTK:@"unlockslider/arrow"];
UIImageView *arrowView = [[UIImageView alloc] initWithImage:arrow];
arrowView.center = CGPointMake(CGRectGetWidth(self.scrollView.frame) + 25, CGRectGetHeight(self.scrollView.frame)/2.0f);
@@ -136,15 +136,12 @@ - (void) _setupView{
self.textLabel.userInteractionEnabled = NO;
[self.scrollView addSubview:self.textLabel];
-
-
}
- (void) renderScreen{
self.alpha = 0;
-
CGPoint p = [self convertPoint:self.superview.bounds.origin fromView:self.superview];
UIGraphicsBeginImageContextWithOptions(self.backgroundView.frame.size, NO, 0);
@@ -154,15 +151,12 @@ - (void) renderScreen{
CGContextTranslateCTM(context, p.x, p.y);
[self.superview.layer renderInContext:context];
-
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
CGContextRestoreGState(context);
UIGraphicsEndImageContext();
newImage = [newImage imageByApplyingBlurWithRadius:2 tintColor:nil saturationDeltaFactor:1 maskImage:nil];
-
-
-
+
self.backgroundView.image = newImage;
self.alpha = 1;
}
@@ -183,12 +177,20 @@ - (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
}
- (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
-
- if(!decelerate)
- [self _resetShimmer];
+ if(!decelerate) [self _resetShimmer];
}
+- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
+ if(self.mode == TKSlideToUnlockViewModeDisabled){
+ scrollView.scrollEnabled = NO;
+ scrollView.userInteractionEnabled = NO;
+ scrollView.scrollEnabled = YES;
+ scrollView.userInteractionEnabled = YES;
+ AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
+ }
+}
+
- (void) resetSlider:(BOOL)animated{
[self.scrollView setContentOffset:CGPointMake(CGRectGetWidth(self.scrollView.frame), 0) animated:animated];
}
@@ -197,6 +199,14 @@ - (void) resetSlider:(BOOL)animated{
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
id white = (id)[UIColor whiteColor].CGColor;
self.textLabel.textHighlightLayer.colors = @[white,white,white,white,white];
+
+ if(self.mode == TKSlideToUnlockViewModeDisabled){
+ self.stashedBackgroundColor = self.scrollView.backgroundColor;
+ [UIView beginAnimations:nil context:nil];
+ self.scrollView.backgroundColor = [UIColor colorWithRed:233/255.0f green:52/255.0f blue:41/255.0f alpha:0.7];
+ [UIView commitAnimations];
+ }
+
}
@@ -209,9 +219,27 @@ - (void) _resetShimmer{
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[self _resetShimmer];
+
+ if(self.mode == TKSlideToUnlockViewModeDisabled){
+ [UIView beginAnimations:nil context:nil];
+ self.scrollView.backgroundColor = self.stashedBackgroundColor;
+ [UIView commitAnimations];
+ [self resetSlider:YES];
+ }
}
-
+- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
+ [super touchesCancelled:touches withEvent:event];
+
+ [self _resetShimmer];
+
+ if(self.mode == TKSlideToUnlockViewModeDisabled){
+ [UIView beginAnimations:nil context:nil];
+ self.scrollView.backgroundColor = self.stashedBackgroundColor;
+ [UIView commitAnimations];
+ [self resetSlider:YES];
+ }
+}

0 comments on commit 85116f4

Please sign in to comment.