TOPasscodeView.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /* Customizable Accessory Views */
  45. @property (nonatomic, strong, nullable) UIView *titleView;
  46. @property (nonatomic, strong, nullable) UIButton *leftButton;
  47. @property (nonatomic, strong, nullable) UIButton *rightButton;
  48. /* The default views always shown in this view */
  49. @property (nonatomic, readonly) UILabel *titleLabel;
  50. @property (nonatomic, readonly) TOPasscodeInputField *inputField;
  51. @property (nonatomic, readonly) TOPasscodeKeypadView *keypadView;
  52. /* Overrides for theming the various elements. */
  53. @property (nonatomic, strong, nullable) UIColor *titleLabelColor;
  54. @property (nonatomic, strong, nullable) UIColor *inputProgressViewTintColor;
  55. @property (nonatomic, strong, nullable) UIColor *keypadButtonBackgroundColor;
  56. @property (nonatomic, strong, nullable) UIColor *keypadButtonTextColor;
  57. @property (nonatomic, strong, nullable) UIColor *keypadButtonHighlightedTextColor;
  58. /* Horizontal inset from edge of keypad view to button center */
  59. @property (nonatomic, readonly) CGFloat keypadButtonInset;
  60. /* An animatable property for animating the non-translucent subviews */
  61. @property (nonatomic, assign) CGFloat contentAlpha;
  62. /* The passcode currently entered into this view */
  63. @property (nonatomic, copy, nullable) NSString *passcode;
  64. /* The default layout object controlling the
  65. sizing and placement of all this view's child elements. */
  66. @property (nonatomic, strong, null_resettable) TOPasscodeViewContentLayout *defaultContentLayout;
  67. /* As needed, additional layout objects that will be checked and used in priority over the default content layout. */
  68. @property (nonatomic, strong, nullable) NSArray<TOPasscodeViewContentLayout *> *contentLayouts;
  69. /* Callback triggered each time the user taps a key */
  70. @property (nonatomic, copy, nullable) void (^passcodeDigitEnteredHandler)(void);
  71. /* Callback triggered when the user has finished entering the passcode */
  72. @property (nonatomic, copy, nullable) void (^passcodeCompletedHandler)(NSString *passcode);
  73. /*
  74. Create a new instance with one of the style types
  75. @param style The visual style of the passcode view.
  76. @param type The type of passcode to accept.
  77. */
  78. - (instancetype)initWithStyle:(TOPasscodeViewStyle)style passcodeType:(TOPasscodeType)type;
  79. /*
  80. Resize the view and all subviews for the optimum size to fit a super view of the suplied width.
  81. @param size The size of the view to which this view.
  82. */
  83. - (void)sizeToFitSize:(CGSize)size;
  84. /*
  85. Reset the passcode to nil and optionally play animation / vibration to match
  86. @param animated Play a shaking animation to reset the passcode.
  87. @param impact On supported devices, play a small reset vibration as well.
  88. */
  89. - (void)resetPasscodeAnimated:(BOOL)animated playImpact:(BOOL)impact;
  90. /*
  91. Delete the last character from the passcode
  92. @param animated Whether the delete operation is animated or not.
  93. */
  94. - (void)deleteLastPasscodeCharacterAnimated:(BOOL)animated;
  95. /*
  96. Animate the transition between horizontal and vertical layouts
  97. @param horizontalLayout Whether to lay out the content vertically or horizontally.
  98. @param animated Whether the transition is animated or not.
  99. @param duration The duration of the animation
  100. */
  101. - (void)setHorizontalLayout:(BOOL)horizontalLayout animated:(BOOL)animated duration:(CGFloat)duration;
  102. @end
  103. NS_ASSUME_NONNULL_END