SideViewManager 0.5.0

SideViewManager 0.5.0

Andrew Boryk维护。



SideViewManager

CI Status Version License Platform

描述

SideViewManager允许开发者使用单依赖项并在一行中添加滑动进出功能。 SideViewManager允许自定义打开和关闭屏幕的帧,因此“打开”和“关闭”的位置可以由开发者定义。此外,还有滑动打开和关闭视图以及点击关闭视图的手势。

目录

示例

要运行示例项目,请克隆仓库,然后首先从示例目录运行pod install

要求

  • 需要iOS 8.0或更高版本
  • 需要自动引用计数(ARC)

特性

  • 在屏幕上滑动打开或关闭视图
  • 自定义打开和关闭位置
  • 轻触即可关闭
  • 手动显示和关闭
  • 委托监听 SideView 的移动

未来特性

  • 创建一个issue来开始讨论要添加的特性。我希望这个组件既轻量,又多功能。

安装

SideViewManager通过CocoaPods提供。要安装它,只需将以下行添加到您的Podfile中

pod 'SideViewManager'

您可以使用以下行将SideViewManager导入到类中

import SideViewManager

使用

初始化

初始化SideViewManager有两种方法,一种是使用UIViewController(管理器将与控制器的view协作)或使用UIView。然后,视图还必须提供endingFramestartingFrame。这些框架基本上指定了屏幕在转换之间所跨越的两个位置。

let startingFrame = CGRect(x: self.view.frame.width, y: 0, width: self.view.frame.width, height: self.view.frame.height)
let endingFrame = self.view.frame

// Initialize with controller
let sideController = UIViewController()
let manager = SideViewManager(controller: sideController, startingFrame: startingFrame, endingFrame: endingFrame)

// Initialize with view
let sideView = UIView()
let manager = SideViewManager(view: sideView, startingFrame: startingFrame, endingFrame: endingFrame)

有可供使用的手势,用于在屏幕上滑动视图和通过点击来关闭视图。这些值应该在您的视图出现后设置,因此最好在您的viewDidAppear(anaimated:)函数中设置。

// Allows the view to be swipable between on and off frames
manager.setSwipeGesture(isEnabled: true)

// Allows the view to be tapped to dismiss
manager.setDismissGesture(isEnabled: true)

接下来,您可以设置SideViewManager实例上的swipeDirection以指定屏幕在屏幕上滑动和关闭时的方向。SideViewManager的滑动手势是双向的,因此滑动方向可以是.horizontal(左和右)或.vertical(上和下)。默认情况下,swipeDirection是水平。

manager.swipeDirection = .horizontal
manager.swipeDirection = .vertical

最后,在用法方面,有手动显示和隐藏侧边视图以及手动设置侧边视图偏移量的函数。

// Presents the sideView with an animation speed of 1 second. 
// By default, the animation speed is 0.25. 
// To remove animation set the animationDuration value to 0.
manager.present(animationDuration: 1.0)

// Dismisses the sideView with an animation speed of 0.5 seconds. 
// By default, the animation speed is 0.25.
// To remove animation set the animationDuration value to 0.
manager.dismiss(animationDuration: 0.5)

// Moves the sideView off screen (0 is off-screen, 1 is on-screeen, 0.5 is halfway, etc.)
// Set the duration of time it takes to move the sideView to this position.
manager.move(to: 0.0, duration: 1.0)

委托

有两个委托方法用于监听对SideViewManager的更改。

// The SideViewManager did finish moving to a given offset, where 0 is off-screen, 1 is on-screen, and values can vary between 0 and 1.
func didFinishAnimating(to offset: CGFloat)

/// Listen for whether a gesture (dismiss or swipe) in the SideViewManager has been enabled/disabled
func didChange(gesture: UIGestureRecognizer, to isEnabled: Bool)

作者

Andrew Boryk, [email protected]

在Twitter上与我联系: @TrepIsLife alt text

许可

SideViewManager遵循MIT许可。有关更多信息,请参阅LICENSE文件。