Skip to content

Commit 406e77b

Browse files
committed
Refactored to account for iPhone
1 parent aeeb477 commit 406e77b

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

TOPasscodeViewController/TOPasscodeViewController.m

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ - (void)setUpAccessoryButtons
175175
}
176176
}
177177

178-
[self updateAccessoryButtonFontsForWidth:self.view.bounds.size.width];
178+
[self updateAccessoryButtonFontsForSize:self.view.bounds.size];
179179
}
180180

181181
#pragma mark - View Management -
@@ -202,21 +202,15 @@ - (void)viewDidAppear:(BOOL)animated
202202
- (void)viewDidLayoutSubviews
203203
{
204204
CGSize bounds = self.view.bounds.size;
205-
CGFloat width = bounds.width;
206-
207-
// If on an iPhone (and we're potentially rotated), work out the minimum width we can be
208-
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
209-
width = MIN(bounds.width, bounds.height);
210-
}
211205

212206
// Update the accessory button sizes
213-
[self updateAccessoryButtonFontsForWidth:width];
207+
[self updateAccessoryButtonFontsForSize:bounds];
214208

215209
// Re-layout the accessory buttons
216-
[self layoutAccessoryButtonsForWidth:width];
210+
[self layoutAccessoryButtonsForSize:bounds];
217211

218212
// Resize the pin view to scale to the new size
219-
[self.passcodeView sizeToFitWidth:width];
213+
[self.passcodeView sizeToFitSize:bounds];
220214

221215
// Re-center the pin view
222216
CGRect frame = self.passcodeView.frame;
@@ -292,8 +286,13 @@ - (void)applyThemeForStyle:(TOPasscodeViewStyle)style
292286
self.backgroundView.backgroundColor = isDark ? [UIColor colorWithWhite:0.1f alpha:1.0f] : [UIColor whiteColor];
293287
}
294288

295-
- (void)updateAccessoryButtonFontsForWidth:(CGFloat)width
289+
- (void)updateAccessoryButtonFontsForSize:(CGSize)size
296290
{
291+
CGFloat width = size.width;
292+
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
293+
width = MIN(size.width, size.height);
294+
}
295+
297296
CGFloat pointSize = 17.0f;
298297
if (width < TOPasscodeViewContentSizeMedium) {
299298
pointSize = 14.0f;
@@ -310,10 +309,12 @@ - (void)updateAccessoryButtonFontsForWidth:(CGFloat)width
310309
self.rightAccessoryButton.titleLabel.font = accessoryFont;
311310
}
312311

313-
- (void)layoutAccessoryButtonsForWidth:(CGFloat)width
312+
- (void)layoutAccessoryButtonsForSize:(CGSize)size
314313
{
315314
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) { return; }
316315

316+
CGFloat width = MIN(size.width, size.height);
317+
317318
CGFloat verticalInset = 54.0f;
318319
if (width < TOPasscodeViewContentSizeMedium) {
319320
verticalInset = 37.0f;

TOPasscodeViewController/Views/Main/TOPasscodeView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ NS_ASSUME_NONNULL_BEGIN
7373
- (instancetype)initWithStyle:(TOPasscodeViewStyle)style passcodeType:(TOPasscodeType)type;
7474

7575
/* Resize the view and all subviews for the optimum size to fit a super view of the suplied width. */
76-
- (void)sizeToFitWidth:(CGFloat)width;
76+
- (void)sizeToFitSize:(CGSize)size;
7777

7878
/* Reset the passcode to nil and optionally play animation / vibration to match */
7979
- (void)resetPasscodeAnimated:(BOOL)animated playImpact:(BOOL)impact;

TOPasscodeViewController/Views/Main/TOPasscodeView.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,13 @@ - (void)layoutSubviews
137137
}
138138
}
139139

140-
- (void)sizeToFitWidth:(CGFloat)width
140+
- (void)sizeToFitSize:(CGSize)size
141141
{
142+
CGFloat width = size.width;
143+
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
144+
width = MIN(size.width, size.height);
145+
}
146+
142147
NSMutableArray *layouts = [NSMutableArray array];
143148
[layouts addObject:self.defaultContentLayout];
144149
[layouts addObjectsFromArray:self.contentLayouts];

0 commit comments

Comments
 (0)