用于创建可拖动视图的可自定义框架

CFNotify

特拉维斯分行
GitHub 问题
迅速
GitHub 分叉
GitHub 明星
GitHub 许可证
迦太基兼容
可可豆荚

CFNotify 是用 Swift 编写的。使用UIKit Dynamics作为动画师。它可以使任何对象可拖动可抛出。该库主要用于应用内通知警报。让我们以更易玩和有趣的方式注意到并提醒您的用户!UIView

演示1
Demo2
Demo3

Features

  • [x] Work with ANY object !UIView
  • [x] Using UIKit Dynamics. Light and Smooth !
  • [x] Highly Customizable
  • [x] Included three ready to use views: , , CyberViewClassicViewToastView
  • [x] Simple to implement

Requirements

  • Swift 4.0+
  • Xcode 9
  • iOS 9.0+

Change Log

Please read CHANGELOG.md.

Installation

  • Carthage (Recommended)

    Add the following lines into Cartfile

    #CFNotify
    github "JT501/CFNotify"
    
    Bash

    Run and then add CFNotify.framework and CFResources.bundle into your projectcarthage update

  • Cocoapods

    Add the following lines into Podfile

    pod "CFNotify"
    
    Ruby

Getting Started

There is an example project inside the source code. You are suggested to have a look first and get familiar with this framework.

The Basics

This is the basic function with all default settings, design your own or use CFNotifyView to create one easily.UIView

CFNotify.present(view: UIView)
Swift

If you need more custom settings, create your own Config and use the following function.

CFNotify.present(config: Config, view: UIView)
Swift

if you want custom action, use the following function. (If you use tapHandler, it will override the default tap to hide action)tap

CFNotify.present(config: Config, view: UIView, tapHandler: (()->Void)?)
Swift

CFNotify will put all the views to be shown in queue (First In First Out).
You can hide the view programmatically using the following functions.

CFNotify.hide() // hide the current view

CFNotify.hideAll() // hide all the views in queue (Clear the queue)
Swift

CFNotifyView

You can create an alert view quickly and easily by using class.CFNotifyView

CFNotifyView included 3 views currently: Cyber, Classic, Toast.

Each style has 4 themes: , , , InfoSuccessFailWarning

Each theme has 2 styles: and LightDark

  • Cyber

    CyberView
    // Use Pre-set theme
    let cyberView = CFNotifyView.cyberWith(title: "Title",
                                            body: "Body",
                                           theme: .info(.light))
    
    //More customizations
    let customCyberView = CFNotifyView.cyberWith(titleFont: UIFont,
                                                titleColor: UIColor,
                                                  bodyFont: UIFont,
                                                 bodyColor: UIColor,
                                           backgroundColor: UIColor,
                                                 blurStyle: UIBlurEffectStyle)
    
    Swift
  • Classic

    ClassicView
    // Use Pre-set theme
    let classicView = CFNotifyView.classicWith(title: "Title",
                                                body: "Body",
                                               theme: .success(.light))
    
    //More customizations
    let customClassicView = CFNotifyView.classicWith(titleFont: UIFont,
                                                    titleColor: UIColor,
                                                      bodyFont: UIFont,
                                                     bodyColor: UIColor,
                                               backgroundColor: UIColor)
    
    Swift
  • Toast

    ToastView
    // Use Pre-set theme
    let toastView = CFNotifyView.toastWith(text: "Text",
                                          theme: .fail(.dark))
    
    //More customizations
    let customToastView = CFNotifyView.toastWith(text: String,
                                             textFont: UIFont,
                                            textColor: UIColor,
                                      backgroundColor: UIColor)                                    
    
    Swift

Config

You can config using class. class included lots of properties, the following three are the most common:CFNotifyConfigConfig

  • initPosition : where the view is born
  • appearPosition : where the view appear position
  • hideTime : the view will automatically hide after (default is 3 sec)hideTime

Example:

var classicViewConfig = CFNotify.Config()
classicViewConfig.initPosition = .top(.random) //the view is born at the top randomly out of the boundary of screen
classicViewConfig.appearPosition = .top //the view will appear at the top of screen
classicViewConfig.hideTime = .never //the view will never automatically hide
Swift

Delegate

CFNotify provides Delegate methods for some of common events.
You need to conform to the .
CFNotifyDelegate

func cfNotifyDidAppear() {}

func cfNotifyStartDragging(atPoint: CGPoint) {}

func cfNotifyIsDragging(atPoint: CGPoint) {}

func cfNotifyEndDragging(atPoint: CGPoint) {}

func cfNotifyDidDisappear() {}

func cfNotifyIsTapped() {}
Swift

To-Do List

  • [ ] Add SPM support
  • [ ] Improve the example app
  • [ ] Add alert view with buttons
  • [ ] Full documentation

Bugs and issues

If you find any bugs or encounter some issues regard to this framework, please feel free to open a new issue in Issues page.

Contribute

You are welcome to contribute into this project, feel free to Pull Request.

License

CFNotify is released under an MIT License. See LICENSE for details.

GitHub

https://github.com/JT501/CFNotify