Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

HWPanModal presents controller from bottom and drag to dismiss, high customize. iOS13 default modalPresentationStyle. 任意形式的底部弹框动画;头条、知乎、抖音弹出评论效果;地图浮层,iOS13 present默认模态效果。

License

NotificationsYou must be signed in to change notification settings

HeathWang/HWPanModal

Repository files navigation

codebeat badge

HWPanModal is used to present controller and drag to dismiss. Similar with iOS13 default present Modal style.

Inspired byPanModal, thanks.

中文文档说明

My another project for pop controller:HWPopController

Snapshoot

BasicBlur backgroundKeyboard handleApp demo

Index

Features

  1. Supports any type ofUIViewController to present.
  2. Support View which inherit fromHWPanModalContentView to present.
  3. Seamless transition between modal and content.
  4. Support two kinds of dismissal gestureRecognizer interaction
    1. Pan gesture direction up&down
    2. Pan gesture direction right, you can swipe on screen edge to dismiss controller.
  5. Support write your own animation for presenting VC.
  6. Support config animationDuration,AnimationOptions,springDamping.
  7. Support config background alpha orblur background. Note: Dynamic change blur effect ONLY works on iOS9.0+.
  8. Show / hide corner, indicator.
  9. Auto handle UIKeyboard show/hide.
  10. Hight customize indicator view.
  11. Touch event response can pass through to presenting VC.
  12. Config presented view shadow style.

More config pls seeHWPanModalPresentable.h declare.

What's different between UIViewController and HWPanModalContentView to present ?

From version 0.6.0, this framework support usingHWPanModalContentView to present from bottom, that means we can add subview(inherit fromHWPanModalContentView) to the target view that you want to show.

The different isHWPanModalContentView is just a view, and support some animations, unlike present ViewController, you will got ViewController life circle, and navigation stack.

HWPanModalContentView limit:

  • Currently not support screen rotation.
  • Not support edge horizontal pan to dismiss.
  • Not support customize presentingVC animation. (There is no presentingVC for view).

TODO

  • Handle keyboard show&dismiss.
  • High customize indicator view.
  • Edge Interactive dismissal can work on full screen and configable distance to left edge.
  • Touch event can response to presenting VC, working on it.
  • Strip the presented view container view, make it can use directly.

Compatibility

iOS 8.0+, support Objective-C & Swift.

Installation

pod'HWPanModal','~> 0.9.9'

How to use

How to present UIViewController from bottom

Your UIViewController need to conformHWPanModalPresentable. If you use default, nothing more will be written.

#import<HWPanModal/HWPanModal.h>@interfaceHWBaseViewController () <HWPanModalPresentable>@end@implementationHWBaseViewController- (void)viewDidLoad {    [superviewDidLoad];// Do any additional setup after loading the view.}#pragma mark - HWPanModalPresentable- (PanModalHeight)longFormHeight {returnPanModalHeightMake(PanModalHeightTypeMaxTopInset,44);}@end

Where you need to present this Controller.

#import<HWPanModal/HWPanModal.h>[selfpresentPanModal:[HWBaseViewControllernew]];

yeah! Easy.

Change state, scrollView contentOffset, reload layout. IMPORTANT!

When You present you Controller, you can change the UI.Refer toUIViewController+Presentation.h.

  • Change the state between short and long form. call- (void)hw_panModalTransitionTo:(PresentationState)state;
  • Change ScrollView ContentOffset. call- (void)hw_panModalSetContentOffset:(CGPoint)offset;
  • Reload layout. call- (void)hw_panModalSetNeedsLayoutUpdate;
    • Note: When your scrollable changed it's contentSize, youMUST reload the layout.

Custom Presenting VC Animation

Some guys want to animate Presenting VC when present/dismiss.

  1. Create object conformsHWPresentingViewControllerAnimatedTransitioning .

    @interfaceHWMyCustomAnimation :NSObject <HWPresentingViewControllerAnimatedTransitioning>@end@implementationHWMyCustomAnimation- (void)presentAnimateTransition:(id<HWPresentingViewControllerContextTransitioning>)transitionContext {NSTimeInterval duration = [transitionContexttransitionDuration];    UIViewController *fromVC = [transitionContextviewControllerForKey:UITransitionContextFromViewControllerKey];// replace it.    [UIViewanimateWithDuration:durationdelay:0usingSpringWithDamping:0.8initialSpringVelocity:0options:UIViewAnimationOptionCurveEaseInOutanimations:^{        fromVC.view.transform =CGAffineTransformMakeScale(0.95,0.95);    }completion:^(BOOL finished) {            }];}- (void)dismissAnimateTransition:(id<HWPresentingViewControllerContextTransitioning>)transitionContext {// no need for using animating block.    UIViewController *toVC = [contextviewControllerForKey:UITransitionContextToViewControllerKey];    toVC.view.transform = CGAffineTransformIdentity;}@end
  2. Overwrite below two method.

    - (PresentingViewControllerAnimationStyle)presentingVCAnimationStyle {return PresentingViewControllerAnimationStyleCustom;}- (id<HWPresentingViewControllerAnimatedTransitioning>)customPresentingVCAnimation {return self.customAnimation;}- (HWMyCustomAnimation *)customAnimation {if (!_customAnimation) {        _customAnimation = [HWMyCustomAnimationnew];    }return _customAnimation;}

Custom your own indicator view

You just need to create your own UIView, then adoptHWPanModalIndicatorProtocol.

In your presented controller, return it:

- (nullable UIView <HWPanModalIndicatorProtocol> *)customIndicatorView {    HWTextIndicatorView *textIndicatorView = [HWTextIndicatorViewnew];return textIndicatorView;}

Here isHWTextIndicatorView code:

@interfaceHWTextIndicatorView :UIView <HWPanModalIndicatorProtocol>@end@interfaceHWTextIndicatorView ()@property (nonatomic,strong) UILabel *stateLabel;@end@implementationHWTextIndicatorView- (instancetype)initWithFrame:(CGRect)frame {    self = [superinitWithFrame:frame];if (self) {// init the _stateLabel        [selfaddSubview:_stateLabel];    }return self;}- (void)didChangeToState:(HWIndicatorState)state {switch (state) {case HWIndicatorStateNormal: {            self.stateLabel.text =@"Please pull down to dismiss";            self.stateLabel.textColor = [UIColorwhiteColor];        }break;case HWIndicatorStatePullDown: {            self.stateLabel.text =@"Keep pull down to dismiss";            self.stateLabel.textColor = [UIColorcolorWithRed:1.000green:0.200blue:0.000alpha:1.00];        }break;    }}- (CGSize)indicatorSize {returnCGSizeMake(200,18);}- (void)setupSubviews {    self.stateLabel.frame = self.bounds;}@end

How to use HWPanModalContentView

You should always inherit fromHWPanModalContentView.HWPanModalContentView conformsHWPanModalPresentable like the way using UIViewController.

@interfaceHWSimplePanModalView :HWPanModalContentView@end@implementationHWSimplePanModalView- (instancetype)initWithFrame:(CGRect)frame {    self = [superinitWithFrame:frame];if (self) {// add view and layout.    }return self;}// present it.HWSimplePanModalView *simplePanModalView = [HWSimplePanModalViewnew];[simplePanModalViewpresentInView:nil];

Example

  1. Clone this git.
  2. open the terminal, runpod install
  3. Double click HWPanModal.xcworkspace, and select a target to run.
I have wrote bothpureObjective-C &SwiftExamples , for most of the framework functions.

Star History

Star History Chart

Contact Me

Heath Wangyishu.jay@gmail.com

WeChat

Change Log

Click Me

License

HWPanModal is released under a MIT License. See LICENSE file for details.

About

HWPanModal presents controller from bottom and drag to dismiss, high customize. iOS13 default modalPresentationStyle. 任意形式的底部弹框动画;头条、知乎、抖音弹出评论效果;地图浮层,iOS13 present默认模态效果。

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp