@@ -52,7 +52,9 @@ - (instancetype)initWithStyle:(TOPasscodeInputFieldStyle)style
52
52
53
53
- (void )setUp
54
54
{
55
+ self.backgroundColor = [UIColor clearColor ];
55
56
_submitButtonSpacing = 4 .0f ;
57
+ _submitButtonVerticalSpacing = 5 .0f ;
56
58
}
57
59
58
60
- (void )setUpForStyle : (TOPasscodeInputFieldStyle)style
@@ -86,6 +88,9 @@ - (void)sizeToFit
86
88
CGRect frame = self.frame ;
87
89
[self .inputField sizeToFit ];
88
90
frame.size = self.inputField .frame .size ;
91
+ if (self.horizontalLayout ) {
92
+ frame.size .height += self.submitButtonVerticalSpacing + CGRectGetHeight (self.submitButton .frame );
93
+ }
89
94
self.frame = CGRectIntegral (frame);
90
95
}
91
96
@@ -97,8 +102,14 @@ - (void)layoutSubviews
97
102
98
103
[self .submitButton sizeToFit ];
99
104
CGRect frame = self.submitButton .frame ;
100
- frame.origin .x = CGRectGetMaxX (self.bounds ) + self.submitButtonSpacing ;
101
- frame.origin .y = (CGRectGetHeight (self.bounds ) - CGRectGetHeight (frame)) * 0 .5f ;
105
+ if (!self.horizontalLayout ) {
106
+ frame.origin .x = CGRectGetMaxX (self.bounds ) + self.submitButtonSpacing ;
107
+ frame.origin .y = (CGRectGetHeight (self.bounds ) - CGRectGetHeight (frame)) * 0 .5f ;
108
+ }
109
+ else {
110
+ frame.origin .x = (CGRectGetWidth (self.frame ) - frame.size .width ) * 0 .5f ;
111
+ frame.origin .y = CGRectGetMaxY (self.inputField .frame ) + self.submitButtonVerticalSpacing ;
112
+ }
102
113
self.submitButton .frame = CGRectIntegral (frame);
103
114
}
104
115
@@ -124,6 +135,7 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
124
135
{
125
136
CGRect frame = self.bounds ;
126
137
frame.size .width += self.submitButton .frame .size .width + (self.submitButtonSpacing * 2 .0f );
138
+ frame.size .height += self.submitButtonVerticalSpacing ;
127
139
128
140
if (CGRectContainsPoint (frame, point)) {
129
141
return YES ;
@@ -340,4 +352,48 @@ - (void)setContentAlpha:(CGFloat)contentAlpha
340
352
self.submitButton .alpha = contentAlpha;
341
353
}
342
354
355
+ - (void )setHorizontalLayout : (BOOL )horizontalLayout
356
+ {
357
+ [self setHorizontalLayout: horizontalLayout animated: NO duration: 0 .0f ];
358
+ }
359
+
360
+ - (void )setHorizontalLayout : (BOOL )horizontalLayout animated : (BOOL )animated duration : (CGFloat)duration
361
+ {
362
+ if (_horizontalLayout == horizontalLayout) {
363
+ return ;
364
+ }
365
+
366
+ UIView *snapshotView = nil ;
367
+
368
+ if (self.submitButton .hidden == NO && animated) {
369
+ snapshotView = [self .submitButton snapshotViewAfterScreenUpdates: NO ];
370
+ snapshotView.frame = self.submitButton .frame ;
371
+ [self addSubview: snapshotView];
372
+ }
373
+
374
+ _horizontalLayout = horizontalLayout;
375
+
376
+ if (!animated) {
377
+ [self sizeToFit ];
378
+ [self setNeedsLayout ];
379
+ return ;
380
+ }
381
+
382
+ self.submitButton .alpha = 0 .0f ;
383
+ [self setNeedsLayout ];
384
+ [self layoutIfNeeded ];
385
+
386
+ id animationBlock = ^{
387
+ self.submitButton .alpha = 1 .0f ;
388
+ snapshotView.alpha = 0 .0f ;
389
+ };
390
+
391
+ id completionBlock = ^(BOOL complete) {
392
+ [snapshotView removeFromSuperview ];
393
+ [self bringSubviewToFront: self .submitButton];
394
+ };
395
+
396
+ [UIView animateWithDuration: duration animations: animationBlock completion: completionBlock];
397
+ }
398
+
343
399
@end
0 commit comments