Files
keyboard/Pods/HWPanModal/Sources/Presentable/HWPanModalPresentable.h

452 lines
14 KiB
C
Raw Normal View History

2025-11-05 22:04:56 +08:00
//
// HWPanModalPresentable.h
// Pods
//
// Created by heath wang on 2019/4/26.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <HWPanModal/HWPanModalHeight.h>
#import <HWPanModal/HWPresentingVCAnimatedTransitioning.h>
#import <HWPanModal/HWPanModalIndicatorProtocol.h>
#import <HWPanModal/HWBackgroundConfig.h>
#import <HWPanModal/HWPanModalShadow.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, PresentationState) {
PresentationStateShort NS_SWIFT_NAME(short),
PresentationStateMedium NS_SWIFT_NAME(medium),
PresentationStateLong NS_SWIFT_NAME(long),
};
typedef NS_ENUM(NSInteger, PresentingViewControllerAnimationStyle) {
// no animation for presentingVC
PresentingViewControllerAnimationStyleNone NS_SWIFT_NAME(none),
// page sheet animation, like iOS13 default modalPresentation style
PresentingViewControllerAnimationStylePageSheet NS_SWIFT_NAME(pageSheet),
// shopping cart animation, like jd/taobao shopping cart animation
PresentingViewControllerAnimationStyleShoppingCart NS_SWIFT_NAME(shoppingCart),
// make your own custom animation
PresentingViewControllerAnimationStyleCustom NS_SWIFT_NAME(custom),
};
/**
* HWPanModalPresentable为present配置协议
* Controller/View适配该协议
* category来默认实现以下所有方法
*
* This Protocol is the core of HWPanModal, we use it to config presentation.
* Default, you don't need to conform all of these methods, just implement what you want to customize.
* All the config has default value, we use a `UIViewController` category to conform `HWPanModalPresentable` protocol.
*/
@protocol HWPanModalPresentable <NSObject>
#pragma mark - ScrollView Config
/**
* scrollView
* ViewController中包含scrollView并且你想scrollView滑动和拖拽手势同时存在scrollView
*
* If your ViewController has a scrollable view(UIScrollView and subclass), and you want pan gesture and scrollable both work, return it.
*/
- (nullable UIScrollView *)panScrollable;
/**
* determine ScrollView scrollEnabled
* default is YES
*/
- (BOOL)isPanScrollEnabled;
/**
* scrollView指示器insets
* Use `panModalSetNeedsLayoutUpdate()` when updating insets.
*/
- (UIEdgeInsets)scrollIndicatorInsets;
/**
* A Boolean value that controls whether the scrollable vertical scroll indicator is visible.
* default is YES.
*/
- (BOOL)showsScrollableVerticalScrollIndicator;
/**
* default is YES.
*/
- (BOOL)shouldAutoSetPanScrollContentInset;
/**
* panScrollable存在scrollView contentSize > (size + bottomLayoutOffset),YES
* NO
*
* If panScrollable exists, and scrollView contentSize > (size + bottomLayoutOffset), auto return YES, otherwise return NO.
* You can make your own logic if you want, and you know what you are doing.
*/
- (BOOL)allowsExtendedPanScrolling;
#pragma mark - Offset/position
/**
* Screen top offset from presented viewController
* Default is topLayoutGuide.length + 21.0.
*/
- (CGFloat)topOffset;
/**
* pan状态为short时候的高度
* default: shortFormHeight = longFormHeight
*/
- (PanModalHeight)shortFormHeight;
/**
* default: mediumFormHeight = longFormHeight
*/
- (PanModalHeight)mediumFormHeight;
/**
* pan状态为long的高度
*/
- (PanModalHeight)longFormHeight;
/**
* `shortFormHeight`
*
* Origin presentation height state, if you have special requirement, change it.
* Default is `shortFormHeight`
*/
- (PresentationState)originPresentationState;
#pragma mark - Animation config
/**
* spring弹性动画数值
* Default is 0.9
*/
- (CGFloat)springDamping;
/**
*
* Default is 0.5 second
*/
- (NSTimeInterval)transitionDuration;
/**
* starting from version 0.6.5, Only works when dismiss
* Default is same as `- (NSTimeInterval)transitionDuration;`
*/
- (NSTimeInterval)dismissalDuration;
/**
* options
* Default is UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState
*/
- (UIViewAnimationOptions)transitionAnimationOptions;
#pragma mark - AppearanceTransition
/**
* If enabled, the presenting VC will invoke viewWillAppear:, viewWillDisappear:
* Default is YES
*/
- (BOOL)shouldEnableAppearanceTransition;
#pragma mark - Background config
/**
* use this object to config background alpha or blur effect
* @return background config object
*/
- (HWBackgroundConfig *)backgroundConfig;
#pragma mark - User Interaction
/**
* bool值控制当pan View状态为long的情况下PanModalHeight = MAX的情况
* YES,long的情况下不能再继续拖动
*/
- (BOOL)anchorModalToLongForm;
/**
* dismiss presented Controller
* YES
*/
- (BOOL)allowsTapBackgroundToDismiss;
/**
* drag操作dismiss presented Controller
* Default is YES
*/
- (BOOL)allowsDragToDismiss;
/// Default is YES, When return NO, and you did set shortForm, user CAN NOT pull down the view.
- (BOOL)allowsPullDownWhenShortState;
/**
min Velocity from Vertical direction that trigger dismiss action.
Default is 300.0
*/
- (CGFloat)minVerticalVelocityToTriggerDismiss;
/**
*
* Default is YES
*/
- (BOOL)isUserInteractionEnabled;
/**
*
* Default is YES
*/
- (BOOL)isHapticFeedbackEnabled;
/**
* presenting ViewController/View(viewpresenting VC/View)
*
* Whether allows touch events passing through the transition container view.
* In some situations, you present the bottom VC/View, and you want to operate the presenting VC/View(mapView, scrollView and etc), enable this func.
*
* Note: You SHOULD MUST dismiss the presented VC in the right time.
*/
- (BOOL)allowsTouchEventsPassingThroughTransitionView;
#pragma mark - Screen left egde interaction
/**
*
* Default is NOnot allowed this user interaction.
*
* Note: Currently only works on UIViewController.
*/
- (BOOL)allowScreenEdgeInteractive;
/**
* Max allowed distance to screen left edge when you want to make screen edge pan interaction
* Default is 0, means it will ignore this limit, full screen left edge pan will work.
* @return distance to left screen edge
*/
- (CGFloat)maxAllowedDistanceToLeftScreenEdgeForPanInteraction;
/**
* When you enabled `- (BOOL)allowScreenEdgeInteractive`, this can work.
* min horizontal velocity to trigger screen edge dismiss if the drag didn't reach 0.5 screen width.
* Default is 500
*/
- (CGFloat)minHorizontalVelocityToTriggerScreenEdgeDismiss;
#pragma mark - Customize presentingViewController animation
/**
* Config presentingViewController animation style, this animations will work for present & dismiss.
* Default is `PresentingViewControllerAnimationStyleNone`.
* @return The animation style.
*/
- (PresentingViewControllerAnimationStyle)presentingVCAnimationStyle;
/**
* presenting ViewController转场动画nil
* 使`- (PresentingViewControllerAnimationStyle)presentingVCAnimationStyle`PresentingViewControllerAnimationStyleCustom
*
* custom presenting ViewController transition animation, default is nil
* Note: If you implement this method and return non nil value, You must implement `- (PresentingViewControllerAnimationStyle)
* presentingVCAnimationStyle` and return PresentingViewControllerAnimationStyleCustom
*/
- (nullable id<HWPresentingViewControllerAnimatedTransitioning>)customPresentingVCAnimation;
#pragma mark - Content UI config
/**
*
* Default is YES
*/
- (BOOL)shouldRoundTopCorners;
/**
*
* Default is 8.0
*/
- (CGFloat)cornerRadius;
/**
* presented content shadow
* Default is None config
*/
- (HWPanModalShadow *)contentShadow;
#pragma mark - Indicator config
/**
* drag指示view
* Default is YESDefault this method depend on `- (BOOL)shouldRoundTopCorners`
*/
- (BOOL)showDragIndicator;
/**
* You can make the indicator customized. Just adopt `HWPanModalIndicatorProtocol`
* Default this method return nil, Then the default indicator will be used.
*/
- (__kindof UIView<HWPanModalIndicatorProtocol> * _Nullable)customIndicatorView;
#pragma mark - Keyboard handle
/**
* When there is text input view exists and becomeFirstResponder, will auto handle keyboard height.
* Default is YES. You can disable it, handle it by yourself.
*/
- (BOOL)isAutoHandleKeyboardEnabled;
/**
The offset that keyboard show from input view's bottom. It works when
`isAutoHandleKeyboardEnabled` return YES.
@return offset, default is 5.
*/
- (CGFloat)keyboardOffsetFromInputView;
#pragma mark - Delegate
#pragma mark - Pan Gesture delegate
/**
* delegate是否需要使拖拽手势生效
* NOdismiss
* YES
*/
- (BOOL)shouldRespondToPanModalGestureRecognizer:(nonnull UIPanGestureRecognizer *)panGestureRecognizer;
/**
* pan recognizer状态为begin/changed时delegate回调
* presented View时
*
*/
- (void)willRespondToPanModalGestureRecognizer:(nonnull UIPanGestureRecognizer *)panGestureRecognizer;
/**
* view frame可能已经变化
* Framework has did finish logic for GestureRecognizer delegate. It will call many times when you darg.
*/
- (void)didRespondToPanModalGestureRecognizer:(nonnull UIPanGestureRecognizer *)panGestureRecognizer;
/**
* view frame可能已经变化
* Framework has did finish logic for GestureRecognizer delegate. It will call many times when you darg.
*/
- (void)didEndRespondToPanModalGestureRecognizer:(nonnull UIPanGestureRecognizer *)panGestureRecognizer;
/**
* dismiss拖拽手势panScrollable的情况下YES
* dismiss手势生效scrollView本身的滑动则不再生效Controller viewscrollView没法拖动了
*
* controller view上添加一个TableViewcontroller view viewA
* viewA有时候无法拖动delegate方法来解决
```
- (BOOL)shouldPrioritizePanModalGestureRecognizer:(UIPanGestureRecognizer *)panGestureRecognizer {
CGPoint loc = [panGestureRecognizer locationInView:self.view];
// check whether user pan action in viewA
if (CGRectContainsPoint(self.viewA.frame, loc)) {
return YES;
}
return NO;
}
```
* NO
*
* This delegate is useful when you want panGestureRecognizer has a high prioritize and
* make scrollable does NOT scroll.
* Example: You controller add a full size tableView, then add viewA on top of your controller view.
* Now you find you can not drag the viewA, use this delegate to resolve problem.
* Please refer to code above this comment.
*
* Default is NO
*/
- (BOOL)shouldPrioritizePanModalGestureRecognizer:(nonnull UIPanGestureRecognizer *)panGestureRecognizer;
/**
* When you pan present controller to dismiss, and the view's y <= shortFormYPos,
* this delegate method will be called.
* @param percent 0 ~ 1, 1 means has dismissed
*/
- (void)panModalGestureRecognizer:(nonnull UIPanGestureRecognizer *)panGestureRecognizer dismissPercent:(CGFloat)percent;
#pragma mark - PresentationState change delegate
/**
* panModal状态
*/
- (BOOL)shouldTransitionToState:(PresentationState)state;
/**
* called when the Transition State will change.
*
*/
- (void)willTransitionToState:(PresentationState)state;
/**
* PresentationState did change callback
*/
- (void)didChangeTransitionToState:(PresentationState)state;
#pragma mark - present delegate
/**
* call when present transition will begin.
*/
- (void)panModalTransitionWillBegin;
/**
* call when present transition did finish.
*/
- (void)panModalTransitionDidFinish;
/**
* call when your custom presented vc has been added to the presentation container.
*/
- (void)presentedViewDidMoveToSuperView;
#pragma mark - Dismiss delegate
/**
* will dismiss
*/
- (void)panModalWillDismiss;
/**
* Did finish dismissing
*/
- (void)panModalDidDismissed;
#pragma mark - DEPRECATED DECLARE
/**
* presentingViewController做动画效果/
* NO
*/
- (BOOL)shouldAnimatePresentingVC DEPRECATED_MSG_ATTRIBUTE("This api has been marked as DEPRECATED on version 0.3.6, please use `- (PresentingViewControllerAnimationStyle)presentingVCAnimationStyle` replaced.");
/**
*
* Default is 0.7
*/
- (CGFloat)backgroundAlpha DEPRECATED_MSG_ATTRIBUTE("This api has been marked as DEPRECATED on version 0.7.0, please use `- (HWBackgroundConfig *)backgroundConfig` replaced.");
/**
* Blur background
* This function can NOT coexist with backgroundAlpha
* Default use backgroundAlpha, Once you set backgroundBlurRadius > 0, blur will work.
* Recommend set the value 10 ~ 20.
* @return blur radius
*/
- (CGFloat)backgroundBlurRadius DEPRECATED_MSG_ATTRIBUTE("This api has been marked as DEPRECATED on version 0.7.0, please use `- (HWBackgroundConfig *)backgroundConfig` replaced.");
/**
* blur background color
* @return color, default is White Color.
*/
- (nonnull UIColor *)backgroundBlurColor DEPRECATED_MSG_ATTRIBUTE("This api has been marked as DEPRECATED on version 0.7.0, please use `- (HWBackgroundConfig *)backgroundConfig` replaced.");
@end
NS_ASSUME_NONNULL_END