PopoverKit 0.2.0

PopoverKit 0.2.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2017 年 9 月
SwiftSwift 版本4.0
SPM支持 SPM

archerzz 维护。



  • archerzz

PopoverKit

一个轻量级的 Swift 库,用于显示弹出窗口。

描述

使用方法

如果您使用 PopoverKit

// Present the view controller using the popover style.        
myPopooverViewController.pop.isNeedPopover = true

// Get the popover presentation controller and configure it.
myPopooverViewController.pop.popoverPresentationController?.sourceView = sender
myPopooverViewController.pop.popoverPresentationController?.sourceRect = sender.bounds
myPopooverViewController.pop.popoverPresentationController?.arrowDirection = .up

如果您使用 UIPopoverPresentationController(System)

// Present the view controller using the popover style.
myPopooverViewController.modalPresentationStyle = .popover
present(myPopooverViewController, animated: true, completion: nil)
 
// Get the popover presentation controller and configure it.
let presentationController = myPopooverViewController.popoverPresentationController
presentationController?.sourceView = myView
presentationController?.sourceRect = sourceRect

如您所见,非常简单,就像系统一样

PopoverTableViewController

  • 初始化您的模型(PureTitleModelNormalModel)
let sortByDate = PureTitleModel(title: "按时间排序")
let sortBySize = PureTitleModel(title: "按大小排序")
let edit = NormalModel(iconName: "ic_note_edit", description: "编辑")
let delete = NormalModel(iconName: "ic_note_delete", description: "删除")
  • 初始化 PopoverTableViewController
let vc = PopoverTableViewController(items: [sortByDate, sortBySize])
vc.pop.isNeedPopover = true
vc.pop.popoverPresentationController?.barButtonItem = sender
vc.pop.popoverPresentationController?.arrowPointY = self.navigationController?.navigationBar.frame.maxY
vc.delegate = self
present(vc, animated: true, completion: nil)
  • 或者自定义您自己的模型(PopoverCellConfiguration)
/// Custom
struct CustomModel: PopoverCellConfiguration {
    
    public var width: CGFloat {
        let cell = AjustFontPopoverCell()
        config(cell: cell)
        let width = cell.systemLayoutSizeFitting(UILayoutFittingCompressedSize).width
        return width
    }
        
    public var resuable: PopoverCellResuable.Type {
        return AjustFontPopoverCell.self
    }
        
    public func config(cell: UITableViewCell) {
        guard let cell  = cell as? AjustFontPopoverCell else {
            return
        }
        // config delegate...
  }
    
    
}

自定义

PopoverConfiguration

属性

public enum PopoverConfiguration.Animation {
    case scale
    case alpha
}
  • arrowSize = CGSize(width: 12, height: 7)
  • cornerRadius = CGFloat(4)
  • animationDuration = TimeInterval(0.25)
  • backgroundColor = UIColor.white
  • dimmingViewColor = UIColor.black.withAlphaComponent(0.35)
  • showDimmingView = true
  • animation: Animation = .scale

要求

  • iOS 8.0+
  • Xcode 8.0+

安装

手动安装

  1. 下载并将 PopoverKit 添加到您的项目中。
  2. 恭喜!

待办事项

  • [] 可定制的动画功能

许可证

PopoverKit 根据 MIT 许可证授权,请参阅 LICENSE 文件。