Skip to content

A lightweight wrapper for easily customizing animation of present non-fullscreen view controller

License

Notifications You must be signed in to change notification settings

qchenqizhi/NonfullscreenPresenter

Repository files navigation

NonfullscreenPresenter

CI Status Version License Platform

A lightweight wrapper for easily customizing animation of present non-fullscreen view controller

Features

  • Customizing transition animation
  • Blured presentingViewController
  • Tap to dismiss
  • Customizing push & pop
  • Interacting present and dismiss with gesture

Usage

  1. Implement the protocol NonfullscreenPresented in presentedViewController:

    extension AlertViewController: NonfullscreenPresented {
    
        func presentedFrame(inContainerView view: UIView) -> CGRect {
            return view.frame
        }
    
        func animation(for transitionType: TransitionType) -> Animation {
            let animation = Animation(animations: {
                if transitionType == .presentation {
                    self.contentView.transform = .identity
                } else {
                    self.contentView.alpha = 0
                    self.contentView.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
                }
            })
    
            return animation
        }
    
        var backgroundStyle: BackgroundStyle { .blur(.dark) }
    
        var backgroundTapToDismissEnabled: Bool { true }
    
    }
  2. Then use this function to present in presentingViewController:

    self.np.present(alert)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Xcode 11.4+
  • Swift 5.2+
  • iOS 11+

Lower versions should work too, I just haven’t tried

Installation

NonfullscreenPresenter is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'NonfullscreenPresenter'

Author

Chen Qizhi, qchenqizhi@gmail.com

License

NonfullscreenPresenter is available under the MIT license. See the LICENSE file for more info.

About

A lightweight wrapper for easily customizing animation of present non-fullscreen view controller

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published