TOPasscodeView.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // TOPasscodeView.h
  3. //
  4. // Copyright 2017 Timothy Oliver. All rights reserved.
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to
  8. // deal in the Software without restriction, including without limitation the
  9. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. // sell copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  21. // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. #import <UIKit/UIKit.h>
  23. #import "TOPasscodeViewControllerConstants.h"
  24. #import "TOPasscodeKeypadView.h"
  25. NS_ASSUME_NONNULL_BEGIN
  26. @class TOPasscodeCircleButton;
  27. @class TOPasscodeInputField;
  28. @class TOPasscodeKeypadView;
  29. @class TOPasscodeViewContentLayout;
  30. /**
  31. The passcode view is the primary content view for the passcode view controller.
  32. On iPad, every view except the background view is a subview of this view.
  33. On iPhone, the auxiliary buttons ('Touch ID', 'Cancel') are managed by the view controller.
  34. */
  35. @interface TOPasscodeView : UIView
  36. /* The visual style of the view */
  37. @property (nonatomic, assign) TOPasscodeViewStyle style;
  38. /* The type of passcode being managed by it */
  39. @property (nonatomic, readonly) TOPasscodeType passcodeType;
  40. /* Whether the content is laid out vertically or horizontally (iPhone only) */
  41. @property (nonatomic, assign) BOOL horizontalLayout;
  42. /* The text in the title view (Default is 'Enter Passcode') */
  43. @property (nonatomic, copy) NSString *titleText;
  44. @property (nonatomic, copy) NSString *subtitleText;
  45. /* Customizable Accessory Views */
  46. @property (nonatomic, strong, nullable) UIView *titleView;
  47. @property (nonatomic, strong, nullable) UIButton *leftButton;
  48. @property (nonatomic, strong, nullable) UIButton *rightButton;
  49. /* The default views always shown in this view */
  50. @property (nonatomic, readonly) UILabel *titleLabel;
  51. @property (nonatomic, readonly) UILabel *subtitleLabel;
  52. @property (nonatomic, readonly) TOPasscodeInputField *inputField;
  53. @property (nonatomic, readonly) TOPasscodeKeypadView *keypadView;
  54. /* Overrides for theming the various elements. */
  55. @property (nonatomic, strong, nullable) UIColor *titleLabelColor;
  56. @property (nonatomic, strong, nullable) UIColor *subtitleLabelColor;
  57. @property (nonatomic, strong, nullable) UIColor *inputProgressViewTintColor;
  58. @property (nonatomic, strong, nullable) UIColor *keypadButtonBackgroundColor;
  59. @property (nonatomic, strong, nullable) UIColor *keypadButtonTextColor;
  60. @property (nonatomic, strong, nullable) UIColor *keypadButtonHighlightedTextColor;
  61. /* Horizontal inset from edge of keypad view to button center */
  62. @property (nonatomic, readonly) CGFloat keypadButtonInset;
  63. /* An animatable property for animating the non-translucent subviews */
  64. @property (nonatomic, assign) CGFloat contentAlpha;
  65. /* The passcode currently entered into this view */
  66. @property (nonatomic, copy, nullable) NSString *passcode;
  67. /* The default layout object controlling the
  68. sizing and placement of all this view's child elements. */
  69. @property (nonatomic, strong, null_resettable) TOPasscodeViewContentLayout *defaultContentLayout;
  70. /* As needed, additional layout objects that will be checked and used in priority over the default content layout. */
  71. @property (nonatomic, strong, nullable) NSArray<TOPasscodeViewContentLayout *> *contentLayouts;
  72. /* Callback triggered each time the user taps a key */
  73. @property (nonatomic, copy, nullable) void (^passcodeDigitEnteredHandler)(void);
  74. /* Callback triggered when the user has finished entering the passcode */
  75. @property (nonatomic, copy, nullable) void (^passcodeCompletedHandler)(NSString *passcode);
  76. /*
  77. Create a new instance with one of the style types
  78. @param style The visual style of the passcode view.
  79. @param type The type of passcode to accept.
  80. */
  81. - (instancetype)initWithStyle:(TOPasscodeViewStyle)style passcodeType:(TOPasscodeType)type;
  82. /*
  83. Resize the view and all subviews for the optimum size to fit a super view of the suplied width.
  84. @param size The size of the view to which this view.
  85. */
  86. - (void)sizeToFitSize:(CGSize)size;
  87. /*
  88. Reset the passcode to nil and optionally play animation / vibration to match
  89. @param animated Play a shaking animation to reset the passcode.
  90. @param impact On supported devices, play a small reset vibration as well.
  91. */
  92. - (void)resetPasscodeAnimated:(BOOL)animated playImpact:(BOOL)impact;
  93. /*
  94. Delete the last character from the passcode
  95. @param animated Whether the delete operation is animated or not.
  96. */
  97. - (void)deleteLastPasscodeCharacterAnimated:(BOOL)animated;
  98. /*
  99. Animate the transition between horizontal and vertical layouts
  100. @param horizontalLayout Whether to lay out the content vertically or horizontally.
  101. @param animated Whether the transition is animated or not.
  102. @param duration The duration of the animation
  103. */
  104. - (void)setHorizontalLayout:(BOOL)horizontalLayout animated:(BOOL)animated duration:(CGFloat)duration;
  105. @end
  106. NS_ASSUME_NONNULL_END