Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions Pod/Classes/DMPasscodeInternalViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
#import "DMPasscodeInternalViewController.h"
#import "DMPasscodeInternalField.h"
#import "DMPasscodeConfig.h"
#import <UIKit/UIKit.h>

#define IDIOM UI_USER_INTERFACE_IDIOM()
#define IPAD UIUserInterfaceIdiomPad
#define BELOW_FIELDS 190
#define ABOVE_FIELDS 65

@interface DMPasscodeInternalViewController () <UITextFieldDelegate>
@end
Expand Down Expand Up @@ -44,14 +50,14 @@ - (void)viewDidLoad {
self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName :_config.navigationBarFont,
NSForegroundColorAttributeName: _config.navigationBarTitleColor};
self.title = _config.navigationBarTitle;

_instructions.frame = CGRectMake(0, 85, self.view.frame.size.width, 30);
_instructions.font = _config.instructionsFont;
_instructions.textColor = _config.descriptionColor;
_instructions.textAlignment = NSTextAlignmentCenter;
_instructions.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:_instructions];

_error.frame = CGRectMake(0, 190, 0, 0); // size set when text is set
_error.font = _config.errorFont;
_error.textColor = _config.errorForegroundColor;
Expand All @@ -63,13 +69,13 @@ - (void)viewDidLoad {
_error.numberOfLines = 0;
_error.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:_error];

CGFloat y_padding = 140;
CGFloat itemWidth = 24;
CGFloat space = 20;
CGFloat totalWidth = (itemWidth * 4) + (space * 3);
CGFloat x_padding = (self.view.bounds.size.width - totalWidth) / 2;

UIView *container = [[UIView alloc] initWithFrame:CGRectMake(x_padding, y_padding, totalWidth, itemWidth)];
container.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
for (int i = 0; i < 4; i++) {
Expand All @@ -80,8 +86,8 @@ - (void)viewDidLoad {
[_textFields addObject:field];
}
[self.view addSubview:container];


_input = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[_input setDelegate:self];
[_input addTarget:self action:@selector(editingChanged:) forControlEvents:UIControlEventEditingChanged];
Expand All @@ -91,6 +97,15 @@ - (void)viewDidLoad {
[_input becomeFirstResponder];
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
{
[self setErrorMessage:_error.text];
if(UIInterfaceOrientationIsPortrait(orientation))
{
_instructions.alpha = 1.0f;
}
}

-(void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
if([_input isFirstResponder]){
[_input resignFirstResponder];
Expand Down Expand Up @@ -119,7 +134,7 @@ - (void)editingChanged:(UITextField *)sender {
DMPasscodeInternalField* field = [_textFields objectAtIndex:i];
field.text = @"";
}

NSString* code = sender.text;
if (code.length == 4) {
[_delegate enteredCode:code];
Expand All @@ -142,11 +157,25 @@ - (void)reset {
- (void)setErrorMessage:(NSString *)errorMessage {
_error.text = errorMessage;
_error.alpha = errorMessage.length > 0 ? 1.0f : 0.0f;


UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

if( IDIOM != IPAD && UIInterfaceOrientationIsLandscape(orientation))
{
_instructions.alpha = errorMessage.length > 0 ? 0.0f : 1.0f;
}

CGSize size = [_error.text sizeWithAttributes:@{NSFontAttributeName: _error.font}];
size.width += 28;
size.height += 28;
_error.frame = CGRectMake(self.view.frame.size.width / 2 - size.width / 2, _error.frame.origin.y, size.width, size.height);

if((orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft) && IDIOM != IPAD ){
_error.frame = CGRectMake(self.view.frame.size.width / 2 - size.width / 2, ABOVE_FIELDS, size.width, size.height);
}
else {
_error.frame = CGRectMake(self.view.frame.size.width / 2 - size.width / 2, BELOW_FIELDS, size.width, size.height);
}
}

- (void)setInstructions:(NSString *)instructions {
Expand Down