Skip to content

Commit

Permalink
Merge commit 'db253d31faef6d958d9a0e48278df0f6491800b3' into ucustom
Browse files Browse the repository at this point in the history
* commit 'db253d31faef6d958d9a0e48278df0f6491800b3':
  Removed redundand code logic.
  Fixed constraints for iOS 8. Fixed status bar offset for iPad and iOS 8.
  Some fixes for iOS 8.
  Moved the dismiss call before the delegate call.
  Fixes issue rolandleth#72
  Updated README. Changed frame depending on status bar visibility.
  • Loading branch information
ukikuchi committed Oct 1, 2014
2 parents a6cfe44 + db253d3 commit f11db61
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ - (void)showLockViewForTestingPasscode {


- (void)showLockViewForChangingPasscode {
[[LTHPasscodeViewController sharedUser] showForChangingPasscodeInViewController:self asModal:NO];
[[LTHPasscodeViewController sharedUser] showForChangingPasscodeInViewController:self asModal:YES];
}


Expand Down
58 changes: 33 additions & 25 deletions LTHPasscodeViewController/LTHPasscodeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#else
// Thanks to Kent Nguyen - https://github.com/kentnguyen
#define kPasscodeCharWidth [_passcodeCharacter sizeWithFont:_passcodeFont].width
#define kFailedAttemptLabelWidth (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? [_failedAttemptLabel.text sizeWithFont:_labelFont].width + 60.0f : [_failedAttemptLabel.text sizeWithFont:_labelFont].width + 30.0f)
#define kFailedAttemptLabelWidth (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? [_failedAttemptLabel.text sizeWithFont:_labelFont].width + 60.0f : [_failedAttemptLabel.text sizeWithFont:_labelFont].width + 20.0f)
#define kFailedAttemptLabelHeight [_failedAttemptLabel.text sizeWithFont:_labelFont].height
#define kEnterPasscodeLabelWidth [_enterPasscodeLabel.text sizeWithFont:_labelFont].width
#endif
Expand Down Expand Up @@ -279,11 +279,15 @@ - (void)viewDidLoad {
}


- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[_passcodeTextField becomeFirstResponder];
}


- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// NSLog(@"layout %@", [self.view performSelector:@selector(recursiveDescription)]);
[_passcodeTextField becomeFirstResponder];

if (!_passcodeTextField.isFirstResponder) [_passcodeTextField becomeFirstResponder];
}


Expand Down Expand Up @@ -444,7 +448,8 @@ - (void)_setupDigitFields {
[_animatingView addSubview:_fourthDigitTextField];
}

-(UITextField *)_makeDigitField{

- (UITextField *)_makeDigitField{
UITextField *field = [[UITextField alloc] initWithFrame:CGRectZero];
field.backgroundColor = _passcodeBackgroundColor;
field.textAlignment = NSTextAlignmentCenter;
Expand Down Expand Up @@ -512,18 +517,18 @@ - (void)updateViewConstraints {

CGFloat yOffsetFromCenter = -self.view.frame.size.height * 0.24;
NSLayoutConstraint *enterPasscodeConstraintCenterX =
[NSLayoutConstraint constraintWithItem: _enterPasscodeLabel
attribute: NSLayoutAttributeCenterX
relatedBy: NSLayoutRelationEqual
toItem: self.view
attribute: NSLayoutAttributeCenterX
multiplier: 1.0f
constant: 0.0f];
[NSLayoutConstraint constraintWithItem: _enterPasscodeLabel
attribute: NSLayoutAttributeCenterX
relatedBy: NSLayoutRelationEqual
toItem: _animatingView
attribute: NSLayoutAttributeCenterX
multiplier: 1.0f
constant: 0.0f];
NSLayoutConstraint *enterPasscodeConstraintCenterY =
[NSLayoutConstraint constraintWithItem: _enterPasscodeLabel
attribute: NSLayoutAttributeCenterY
relatedBy: NSLayoutRelationEqual
toItem: self.view
toItem: _animatingView
attribute: NSLayoutAttributeCenterY
multiplier: 1.0f
constant: yOffsetFromCenter];
Expand All @@ -535,31 +540,31 @@ - (void)updateViewConstraints {
[NSLayoutConstraint constraintWithItem: _firstDigitTextField
attribute: NSLayoutAttributeLeft
relatedBy: NSLayoutRelationEqual
toItem: self.view
toItem: _animatingView
attribute: NSLayoutAttributeCenterX
multiplier: 1.0f
constant: - _horizontalGap * 1.5f - 2.0f];
NSLayoutConstraint *secondDigitX =
[NSLayoutConstraint constraintWithItem: _secondDigitTextField
attribute: NSLayoutAttributeLeft
relatedBy: NSLayoutRelationEqual
toItem: self.view
toItem: _animatingView
attribute: NSLayoutAttributeCenterX
multiplier: 1.0f
constant: - _horizontalGap * 2/3 - 2.0f];
NSLayoutConstraint *thirdDigitX =
[NSLayoutConstraint constraintWithItem: _thirdDigitTextField
attribute: NSLayoutAttributeLeft
relatedBy: NSLayoutRelationEqual
toItem: self.view
toItem: _animatingView
attribute: NSLayoutAttributeCenterX
multiplier: 1.0f
constant: _horizontalGap * 1/6 - 2.0f];
NSLayoutConstraint *fourthDigitX =
[NSLayoutConstraint constraintWithItem: _fourthDigitTextField
attribute: NSLayoutAttributeLeft
relatedBy: NSLayoutRelationEqual
toItem: self.view
toItem: _animatingView
attribute: NSLayoutAttributeCenterX
multiplier: 1.0f
constant: _horizontalGap - 2.0f];
Expand Down Expand Up @@ -688,7 +693,7 @@ - (void)updateViewConstraints {
[NSLayoutConstraint constraintWithItem: _failedAttemptLabel
attribute: NSLayoutAttributeCenterX
relatedBy: NSLayoutRelationEqual
toItem: self.view
toItem: _animatingView
attribute: NSLayoutAttributeCenterX
multiplier: 1.0f
constant: 0.0f];
Expand Down Expand Up @@ -744,7 +749,7 @@ - (void)showLockScreenWithAnimation:(BOOL)animated withLogout:(BOOL)hasLogout an
// UIWindow *mainWindow = [UIApplication sharedApplication].keyWindow;
UIWindow *mainWindow = [UIApplication sharedApplication].windows[0];
[mainWindow addSubview: self.view];
[mainWindow.rootViewController addChildViewController: self];
// [mainWindow.rootViewController addChildViewController: self];
// All this hassle because a view added to UIWindow does not rotate automatically
// and if we would have added the view anywhere else, it wouldn't display properly
// (having a modal on screen when the user leaves the app, for example).
Expand Down Expand Up @@ -788,7 +793,9 @@ - (void)showLockScreenWithAnimation:(BOOL)animated withLogout:(BOOL)hasLogout an
// Add nav bar & logout button if specified
if (hasLogout) {
// Navigation Bar with custom UI
self.navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, mainWindow.frame.origin.y, 320, 64)];
self.navBar =
[[UINavigationBar alloc] initWithFrame:CGRectMake(0, mainWindow.frame.origin.y,
mainWindow.frame.size.width, 64)];
self.navBar.tintColor = self.navigationTintColor;
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
self.navBar.barTintColor = self.navigationBarTintColor;
Expand Down Expand Up @@ -1032,14 +1039,14 @@ - (BOOL)_validatePasscode:(NSString *)typedString {
// App launch/Turning passcode off: Passcode OK -> dismiss, Passcode incorrect -> deny access.
else {
if ([typedString isEqualToString: savedPasscode]) {
if ([self.delegate respondsToSelector: @selector(passcodeWasEnteredSuccessfully)]) {
[self.delegate performSelector: @selector(passcodeWasEnteredSuccessfully)];
}
//Or, if you prefer by notifications:
// Or, if you prefer by notifications:
// [[NSNotificationCenter defaultCenter] postNotificationName: @"passcodeWasEnteredSuccessfully"
// object: self
// userInfo: nil];
[self _dismissMe];
if ([self.delegate respondsToSelector: @selector(passcodeWasEnteredSuccessfully)]) {
[self.delegate performSelector: @selector(passcodeWasEnteredSuccessfully)];
}
}
else {
[self performSelector: @selector(_denyAccess)
Expand Down Expand Up @@ -1256,7 +1263,8 @@ - (void)_applicationDidEnterBackground {
return;
}
if ([self _doesPasscodeExist]) {
if ([_passcodeTextField isFirstResponder]) [_passcodeTextField resignFirstResponder];
if ([_passcodeTextField isFirstResponder])
[_passcodeTextField resignFirstResponder];
// Without animation because otherwise it won't come down fast enough,
// so inside iOS' multitasking view the app won't be covered by anything.
if ([self _timerDuration] <= 0) {
Expand Down

0 comments on commit f11db61

Please sign in to comment.