@@ -52,7 +52,9 @@ - (instancetype)initWithStyle:(TOPasscodeInputFieldStyle)style
5252
5353- (void )setUp
5454{
55+ self.backgroundColor = [UIColor clearColor ];
5556 _submitButtonSpacing = 4 .0f ;
57+ _submitButtonVerticalSpacing = 5 .0f ;
5658}
5759
5860- (void )setUpForStyle : (TOPasscodeInputFieldStyle)style
@@ -86,6 +88,9 @@ - (void)sizeToFit
8688 CGRect frame = self.frame ;
8789 [self .inputField sizeToFit ];
8890 frame.size = self.inputField .frame .size ;
91+ if (self.horizontalLayout ) {
92+ frame.size .height += self.submitButtonVerticalSpacing + CGRectGetHeight (self.submitButton .frame );
93+ }
8994 self.frame = CGRectIntegral (frame);
9095}
9196
@@ -97,8 +102,14 @@ - (void)layoutSubviews
97102
98103 [self .submitButton sizeToFit ];
99104 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+ }
102113 self.submitButton .frame = CGRectIntegral (frame);
103114}
104115
@@ -124,6 +135,7 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
124135{
125136 CGRect frame = self.bounds ;
126137 frame.size .width += self.submitButton .frame .size .width + (self.submitButtonSpacing * 2 .0f );
138+ frame.size .height += self.submitButtonVerticalSpacing ;
127139
128140 if (CGRectContainsPoint (frame, point)) {
129141 return YES ;
@@ -340,4 +352,48 @@ - (void)setContentAlpha:(CGFloat)contentAlpha
340352 self.submitButton .alpha = contentAlpha;
341353}
342354
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+
343399@end
0 commit comments