Skip to content

Commit 311b3a6

Browse files
committed
Perfected main content transition
1 parent 5fd2f07 commit 311b3a6

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

TOPasscodeViewController/Models/TOPasscodeViewContentLayout.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919

2020
/* The Title Label Explaining the Passcode View */
2121
@property (nonatomic, assign) CGFloat titleLabelBottomSpacing; // Space from the title label to the input view
22+
2223
@property (nonatomic, strong) UIFont *titleLabelFont; // The font of the title label
2324

2425
/* Title Label properties when the view is laid out horizontally */
2526
@property (nonatomic, assign) CGFloat titleHorizontalLayoutWidth; // When laid out horizontally, the width of the title view
2627
@property (nonatomic, assign) CGFloat titleHorizontalLayoutSpacing; // The amount of spacing between the title label and the passcode keypad
28+
@property (nonatomic, assign) CGFloat titleViewHorizontalBottomSpacing; // Space from the bottom of the title view when iPhone is horizontal
29+
@property (nonatomic, assign) CGFloat titleLabelHorizontalBottomSpacing; // Spacing from the title label to input view in horizontal mode
2730

2831
/* Circle Row Configuration */
2932
@property (nonatomic, assign) CGFloat circleRowDiameter; // The diameter of each circle representing a PIN number

TOPasscodeViewController/Models/TOPasscodeViewContentLayout.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ + (TOPasscodeViewContentLayout *)defaultScreenContentLayout
2525
contentLayout.titleLabelFont = [UIFont systemFontOfSize: 22.0f];
2626

2727
/* Horizontal title constraints */
28-
contentLayout.titleHorizontalLayoutWidth = 185.0f;
29-
contentLayout.titleHorizontalLayoutSpacing = 16.0f;
28+
contentLayout.titleHorizontalLayoutWidth = 250.0f;
29+
contentLayout.titleHorizontalLayoutSpacing = 35.0f;
30+
contentLayout.titleViewHorizontalBottomSpacing = 20.0f;
31+
contentLayout.titleLabelHorizontalBottomSpacing = 20.0f;
3032

3133
/* Circle Row Configuration */
3234
contentLayout.circleRowDiameter = 15.5f;
@@ -75,6 +77,8 @@ + (TOPasscodeViewContentLayout *)mediumScreenContentLayout
7577
/* Horizontal title constraints */
7678
contentLayout.titleHorizontalLayoutWidth = 185.0f;
7779
contentLayout.titleHorizontalLayoutSpacing = 16.0f;
80+
contentLayout.titleViewHorizontalBottomSpacing = 18.0f;
81+
contentLayout.titleLabelHorizontalBottomSpacing = 18.0f;
7882

7983
/* Circle Row Configuration */
8084
contentLayout.circleRowDiameter = 12.5f;
@@ -121,6 +125,8 @@ + (TOPasscodeViewContentLayout *)smallScreenContentLayout
121125
/* Horizontal title constraints */
122126
contentLayout.titleHorizontalLayoutWidth = 185.0f;
123127
contentLayout.titleHorizontalLayoutSpacing = 16.0f;
128+
contentLayout.titleViewHorizontalBottomSpacing = 18.0f;
129+
contentLayout.titleLabelHorizontalBottomSpacing = 18.0f;
124130

125131
/* Circle Row Configuration */
126132
contentLayout.circleRowDiameter = 12.5f;

TOPasscodeViewController/TOPasscodeViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ - (TOPasscodeView *)passcodeView
451451
[weakSelf keypadButtonTapped];
452452
};
453453

454+
// Set initial layout to horizontal if we're rotated on an iPhone
454455
if (self.passcodeType != TOPasscodeTypeCustomAlphanumeric && UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
455456
CGSize boundsSize = self.view.bounds.size;
456457
_passcodeView.horizontalLayout = boundsSize.width > boundsSize.height;

TOPasscodeViewController/Views/Main/TOPasscodeView.m

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ - (void)setUp
6666
_currentLayout = _defaultContentLayout;
6767
_contentLayouts = @[[TOPasscodeViewContentLayout mediumScreenContentLayout],
6868
[TOPasscodeViewContentLayout smallScreenContentLayout]];
69-
_titleText = @"Enter Passcode";
69+
_titleText = NSLocalizedString(@"Enter Passcode", @"");
7070

7171
// Start configuring views
7272
[self setUpViewForType:self.passcodeType];
@@ -144,36 +144,33 @@ - (void)horizontallyLayoutSubviews
144144
CGSize midViewSize = (CGSize){self.frame.size.width * 0.5f, self.frame.size.height * 0.5f};
145145
CGRect frame = CGRectZero;
146146

147-
// Work out total height of header content
148-
CGFloat headerHeight = 0.0f;
147+
// Work out the y offset, assuming the input field is in the middle
148+
frame.origin.y = midViewSize.height - (self.inputField.frame.size.height * 0.5f);
149+
frame.origin.y -= (self.titleLabel.frame.size.height + self.currentLayout.titleLabelHorizontalBottomSpacing);
150+
151+
// Include offset for title view if present
149152
if (self.titleView) {
150-
headerHeight += self.titleView.frame.size.height;
151-
headerHeight += self.currentLayout.titleViewBottomSpacing;
153+
frame.origin.y -= (self.titleView.frame.size.height + self.currentLayout.titleViewHorizontalBottomSpacing);
152154
}
153155

154-
headerHeight += self.titleLabel.frame.size.height;
155-
headerHeight += self.currentLayout.titleLabelBottomSpacing;
156-
157-
headerHeight += self.inputField.frame.size.height;
158-
159156
// Set initial Y offset
160-
frame.origin.y = midViewSize.height - (headerHeight * 0.5f);
157+
frame.origin.y = MAX(frame.origin.y, 0.0f);
161158

162159
// Set frame of title view
163160
if (self.titleView) {
164161
frame.size = self.titleView.frame.size;
165162
frame.origin.x = (self.currentLayout.titleHorizontalLayoutWidth - frame.size.width) * 0.5f;
166163
self.titleView.frame = CGRectIntegral(frame);
167164

168-
frame.origin.y += (frame.size.height + self.currentLayout.titleViewBottomSpacing);
165+
frame.origin.y += (frame.size.height + self.currentLayout.titleViewHorizontalBottomSpacing);
169166
}
170167

171168
// Set frame of title label
172169
frame.size = self.titleLabel.frame.size;
173170
frame.origin.x = (self.currentLayout.titleHorizontalLayoutWidth - frame.size.width) * 0.5f;
174171
self.titleLabel.frame = CGRectIntegral(frame);
175172

176-
frame.origin.y += (frame.size.height + self.currentLayout.titleLabelBottomSpacing);
173+
frame.origin.y += (frame.size.height + self.currentLayout.titleLabelHorizontalBottomSpacing);
177174

178175
// Set frame of the input field
179176
frame.size = self.inputField.frame.size;

0 commit comments

Comments
 (0)