Skip to content

Commit 5fd2f07

Browse files
committed
Got horizontal rotation roughly working
1 parent 406e77b commit 5fd2f07

File tree

2 files changed

+96
-10
lines changed

2 files changed

+96
-10
lines changed

TOPasscodeViewController/TOPasscodeViewController.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ @interface TOPasscodeViewController () <UIViewControllerTransitioningDelegate>
2525
@property (nonatomic, strong, readwrite) UIButton *biometricButton;
2626
@property (nonatomic, strong, readwrite) UIButton *cancelButton;
2727

28-
29-
3028
@end
3129

3230
@implementation TOPasscodeViewController
@@ -262,9 +260,8 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIVi
262260
// Work out if we need to transition to horizontal
263261
BOOL horizontalLayout = size.height < size.width;
264262

265-
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
266-
[self.passcodeView setHorizontalLayout:horizontalLayout animated:YES duration:context.transitionDuration];
267-
} completion:nil];
263+
// Perform layout animation
264+
[self.passcodeView setHorizontalLayout:horizontalLayout animated:coordinator.animated duration:coordinator.transitionDuration];
268265
}
269266

270267
#pragma mark - View Styling -
@@ -415,8 +412,6 @@ - (void)keyboardWillChangeFrame:(NSNotification *)notification
415412
// Animate the content sliding up and down with the keyboard
416413
[UIView animateWithDuration:animationDuration
417414
delay:0.0f
418-
// usingSpringWithDamping:1.0f
419-
// initialSpringVelocity:1.0f
420415
options:animationCurve
421416
animations:^{ [self.view layoutIfNeeded]; }
422417
completion:nil];
@@ -456,6 +451,11 @@ - (TOPasscodeView *)passcodeView
456451
[weakSelf keypadButtonTapped];
457452
};
458453

454+
if (self.passcodeType != TOPasscodeTypeCustomAlphanumeric && UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
455+
CGSize boundsSize = self.view.bounds.size;
456+
_passcodeView.horizontalLayout = boundsSize.width > boundsSize.height;
457+
}
458+
459459
return _passcodeView;
460460
}
461461

TOPasscodeViewController/Views/Main/TOPasscodeView.m

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ @interface TOPasscodeView ()
1717
/* The current layout object used to configure this view */
1818
@property (nonatomic, weak) TOPasscodeViewContentLayout *currentLayout;
1919

20+
/* The main views */
2021
@property (nonatomic, strong, readwrite) UILabel *titleLabel;
21-
@property (nonatomic, strong, readwrite) TOPasscodeKeypadView *keypadView;
2222
@property (nonatomic, strong, readwrite) TOPasscodeInputField *inputField;
23+
@property (nonatomic, strong, readwrite) TOPasscodeKeypadView *keypadView;
2324

25+
/* The type of passcode we're displaying */
2426
@property (nonatomic, assign, readwrite) TOPasscodeType passcodeType;
2527

2628
@end
@@ -77,7 +79,7 @@ - (void)setUp
7779
}
7880

7981
#pragma mark - View Layout -
80-
- (void)layoutSubviews
82+
- (void)verticallyLayoutSubviews
8183
{
8284
CGSize viewSize = self.frame.size;
8385
CGSize midViewSize = (CGSize){self.frame.size.width * 0.5f, self.frame.size.height * 0.5f};
@@ -137,6 +139,64 @@ - (void)layoutSubviews
137139
}
138140
}
139141

142+
- (void)horizontallyLayoutSubviews
143+
{
144+
CGSize midViewSize = (CGSize){self.frame.size.width * 0.5f, self.frame.size.height * 0.5f};
145+
CGRect frame = CGRectZero;
146+
147+
// Work out total height of header content
148+
CGFloat headerHeight = 0.0f;
149+
if (self.titleView) {
150+
headerHeight += self.titleView.frame.size.height;
151+
headerHeight += self.currentLayout.titleViewBottomSpacing;
152+
}
153+
154+
headerHeight += self.titleLabel.frame.size.height;
155+
headerHeight += self.currentLayout.titleLabelBottomSpacing;
156+
157+
headerHeight += self.inputField.frame.size.height;
158+
159+
// Set initial Y offset
160+
frame.origin.y = midViewSize.height - (headerHeight * 0.5f);
161+
162+
// Set frame of title view
163+
if (self.titleView) {
164+
frame.size = self.titleView.frame.size;
165+
frame.origin.x = (self.currentLayout.titleHorizontalLayoutWidth - frame.size.width) * 0.5f;
166+
self.titleView.frame = CGRectIntegral(frame);
167+
168+
frame.origin.y += (frame.size.height + self.currentLayout.titleViewBottomSpacing);
169+
}
170+
171+
// Set frame of title label
172+
frame.size = self.titleLabel.frame.size;
173+
frame.origin.x = (self.currentLayout.titleHorizontalLayoutWidth - frame.size.width) * 0.5f;
174+
self.titleLabel.frame = CGRectIntegral(frame);
175+
176+
frame.origin.y += (frame.size.height + self.currentLayout.titleLabelBottomSpacing);
177+
178+
// Set frame of the input field
179+
frame.size = self.inputField.frame.size;
180+
frame.origin.x = (self.currentLayout.titleHorizontalLayoutWidth - frame.size.width) * 0.5f;
181+
self.inputField.frame = CGRectIntegral(frame);
182+
183+
// Set the frame of the keypad view
184+
frame.size = self.keypadView.frame.size;
185+
frame.origin.y = 0.0f;
186+
frame.origin.x = self.currentLayout.titleHorizontalLayoutWidth + self.currentLayout.titleHorizontalLayoutSpacing;
187+
self.keypadView.frame = CGRectIntegral(frame);
188+
}
189+
190+
- (void)layoutSubviews
191+
{
192+
if (self.horizontalLayout) {
193+
[self horizontallyLayoutSubviews];
194+
}
195+
else {
196+
[self verticallyLayoutSubviews];
197+
}
198+
}
199+
140200
- (void)sizeToFitSize:(CGSize)size
141201
{
142202
CGFloat width = size.width;
@@ -164,7 +224,7 @@ - (void)sizeToFitSize:(CGSize)size
164224
[self sizeToFit];
165225
}
166226

167-
- (void)sizeToFit
227+
- (void)verticalSizeToFit
168228
{
169229
CGRect frame = self.frame;
170230
frame.size.width = 0.0f;
@@ -217,6 +277,32 @@ - (void)sizeToFit
217277
self.frame = CGRectIntegral(frame);
218278
}
219279

280+
- (void)horizontalSizeToFit
281+
{
282+
CGRect frame = self.frame;
283+
284+
[self.keypadView sizeToFit];
285+
[self.inputField sizeToFit];
286+
287+
frame.size.width = self.currentLayout.titleHorizontalLayoutWidth;
288+
frame.size.width += self.currentLayout.titleHorizontalLayoutSpacing;
289+
frame.size.width += self.keypadView.frame.size.width;
290+
291+
frame.size.height = self.keypadView.frame.size.height;
292+
293+
self.frame = CGRectIntegral(frame);
294+
}
295+
296+
- (void)sizeToFit
297+
{
298+
if (self.horizontalLayout) {
299+
[self horizontalSizeToFit];
300+
}
301+
else {
302+
[self verticalSizeToFit];
303+
}
304+
}
305+
220306
#pragma mark - View Setup -
221307
- (void)setUpViewForType:(TOPasscodeType)type
222308
{

0 commit comments

Comments
 (0)