Navigation Menu

Skip to content
This repository has been archived by the owner on Jan 25, 2020. It is now read-only.

Commit

Permalink
support landscape on iPhone; Issue #38
Browse files Browse the repository at this point in the history
  • Loading branch information
John Flanagan authored and John Flanagan committed Apr 24, 2012
1 parent a7c5c87 commit 40b903e
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 18 deletions.
2 changes: 1 addition & 1 deletion MiniKeePass/AutorotatingTableViewController.m
Expand Up @@ -16,7 +16,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
shouldRotate = YES;
} else {
shouldRotate = interfaceOrientation == UIInterfaceOrientationPortrait;
shouldRotate = interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}

return shouldRotate;
Expand Down
2 changes: 1 addition & 1 deletion MiniKeePass/AutorotatingViewController.m
Expand Up @@ -16,7 +16,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
shouldRotate = YES;
} else {
shouldRotate = interfaceOrientation == UIInterfaceOrientationPortrait;
shouldRotate = interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}

return shouldRotate;
Expand Down
1 change: 0 additions & 1 deletion MiniKeePass/FormViewController.m
Expand Up @@ -159,7 +159,6 @@ - (void)resizeControlsForOrientation:(UIInterfaceOrientation)orientation {
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// Not sure why, but the non-UITableViewCell controls do not seem to get resized during rotation, so adjust here.
[UIView animateWithDuration:duration animations:^{
[self resizeControlsForOrientation:toInterfaceOrientation];
}];
Expand Down
2 changes: 1 addition & 1 deletion MiniKeePass/LockScreenController.h
Expand Up @@ -19,7 +19,7 @@
#import "PinViewController.h"
#import "AutorotatingViewController.h"

@interface LockScreenController : AutorotatingViewController <PinViewControllerDelegate> {
@interface LockScreenController : UIViewController <PinViewControllerDelegate> {
PinViewController *pinViewController;
MiniKeePassAppDelegate *appDelegate;
CGRect visibleFrame;
Expand Down
4 changes: 4 additions & 0 deletions MiniKeePass/LockScreenController.m
Expand Up @@ -82,6 +82,10 @@ - (void)setBackgroundForOrientation:(UIInterfaceOrientation)orientation {
- (void)updateFramesForOrientation:(UIInterfaceOrientation)orientation {
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad || toInterfaceOrientation == UIInterfaceOrientationPortrait;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[UIView animateWithDuration:duration animations:^{
// [self updateFramesForOrientation:toInterfaceOrientation];
Expand Down
2 changes: 2 additions & 0 deletions MiniKeePass/PinViewController.h
Expand Up @@ -24,6 +24,8 @@
UITextField *textField;
NSArray *pinTextFields;
UILabel *textLabel;
UIToolbar *topBar;
UIToolbar *pinBar;
id<PinViewControllerDelegate> delegate;
}

Expand Down
53 changes: 39 additions & 14 deletions MiniKeePass/PinViewController.m
Expand Up @@ -33,9 +33,8 @@ - (id)initWithText:(NSString*)text {
self = [super init];
if (self) {
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];

MiniKeePassAppDelegate *appDelegate = (MiniKeePassAppDelegate *)[[UIApplication sharedApplication] delegate];
CGFloat screenWidth = [appDelegate currentScreenWidth];

CGFloat frameWidth = CGRectGetWidth(self.view.frame);

textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
textField.delegate = self;
Expand All @@ -48,7 +47,7 @@ - (id)initWithText:(NSString*)text {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:UITextFieldTextDidChangeNotification object:textField];

// Create topbar
textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 95)];
textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frameWidth, 95)];
textLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
textLabel.backgroundColor = [UIColor clearColor];
textLabel.textColor = [UIColor whiteColor];
Expand All @@ -57,13 +56,12 @@ - (id)initWithText:(NSString*)text {
textLabel.textAlignment = UITextAlignmentCenter;
textLabel.text = text;

UIToolbar *topBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 95)];
topBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, frameWidth, 95)];
topBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
topBar.barStyle = UIBarStyleBlackTranslucent;
[topBar addSubview:textLabel];

[self.view addSubview:topBar];
[topBar release];

// Create PIN bar
CGFloat pinTextFieldWidth = 61.0f;
Expand All @@ -72,8 +70,8 @@ - (id)initWithText:(NSString*)text {

CGFloat textFieldViewWidth = pinTextFieldWidth * 4 + textFieldSpace * 3;

UIView *textFieldsView = [[UIView alloc] initWithFrame:CGRectMake((screenWidth - textFieldViewWidth) / 2, 22, textFieldViewWidth, pinTextFieldHeight)];
textFieldsView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
UIView *textFieldsView = [[UIView alloc] initWithFrame:CGRectMake((frameWidth - textFieldViewWidth) / 2, 22, textFieldViewWidth, pinTextFieldHeight)];
textFieldsView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

CGFloat xOrigin = 0;

Expand All @@ -99,13 +97,18 @@ - (id)initWithText:(NSString*)text {
[pinTextField3 release];
[pinTextField4 release];

UIToolbar *PINbar= [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 95)];
PINbar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[PINbar setBarStyle:UIBarStyleBlackTranslucent];
[PINbar addSubview:textFieldsView];
pinBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, frameWidth, 95)];
pinBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[pinBar setBarStyle:UIBarStyleBlackTranslucent];
[pinBar addSubview:textFieldsView];

textField.inputAccessoryView = PINbar;
[PINbar release];
textField.inputAccessoryView = pinBar;

UIInterfaceOrientation orientation = self.interfaceOrientation;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
UIInterfaceOrientationIsLandscape(orientation)) {
[self resizeToolbarsToInterfaceOrientation:orientation];
}

// If the keyboard is dismissed, show it again.
// [[NSNotificationCenter defaultCenter] addObserver:self
Expand All @@ -118,13 +121,32 @@ - (id)initWithText:(NSString*)text {
}

- (void)dealloc {
[topBar release];
[pinBar release];
[textField release];
[pinTextFields release];
[textLabel release];
[delegate release];
[super dealloc];
}

- (void)resizeToolbarsToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
CGRect newFrame = topBar.frame;
newFrame.size.height = UIInterfaceOrientationIsPortrait(toInterfaceOrientation) ? 95 : 68;

topBar.frame = newFrame;
textLabel.frame = newFrame;
pinBar.frame = newFrame;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// Nothing needs to be done for the iPad; return
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) return;
[UIView animateWithDuration:duration animations:^{
[self resizeToolbarsToInterfaceOrientation:toInterfaceOrientation];
}];
}

- (UIColor *)backgroundColor {
return self.view.backgroundColor;
}
Expand Down Expand Up @@ -183,6 +205,9 @@ - (void)checkPin:(id)sender {
- (BOOL)becomeFirstResponder {
[super becomeFirstResponder];

// When the PIN screen is presented from the lock screen the bars must be resized before presented
[self resizeToolbarsToInterfaceOrientation:self.interfaceOrientation];

return [textField becomeFirstResponder];
}

Expand Down

0 comments on commit 40b903e

Please sign in to comment.