SlideMenuDovi 1.1.0

SlideMenuDovi 1.1.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2016年9月
SPM支持 SPM

Edouard Roussillon 维护。



  • Edouard Roussillon

SlideMenuDovi

Swift 版本

  • 即将兼容 3.0
  • 兼容 2.3 版本 1.1.0
  • 兼容 2.2 版本 1.0.1

为什么还要另一个 Slide Menu!!!

如果您想要创建除了当前动画之外的特殊动画,SlideMenuDovi 就是为您准备的 :).

如何使用 SlideMenuDovi

首先您需要查看 SliderMenuOptions,这个结构会为您提供完整的选项列表(宽度、不透明度、阴影、状态栏等)

public struct SliderMenuOptions {
    // Define the left side
    public static var leftViewWidth: CGFloat = 242.0
    public static var leftBezelWidth: CGFloat = 16.0
    public static var leftPanFromBezel: Bool = true

    // Define the right side
    public static var rightViewWidth: CGFloat = 242.0
    public static var rightBezelWidth: CGFloat = 16.0
    public static var rightPanFromBezel: Bool = true

    // Type of animation
    public static var animationType: SliderMenuAnimation = SliderMenuAnimationDefault()

    // Menu will open or close only after passing this value
    public static var pointOfNoReturnWidth: CGFloat = 44.0

    // Opacity of the view between the MainViewController and the Menu (Left or Right)
    public static var contentViewOpacity: CGFloat = 0.0

    // Sliding view will be set with a shadow
    public static var shadowOpacity: CGFloat = 1.0
    public static var shadowRadius: CGFloat = 12
    public static var shadowOffset: CGSize = CGSizeMake(0,0)
    public static var shadowColor: UIColor = UIColor.blackColor()

    // Animation duration
    public static var animationDuration: CGFloat = 0.4

    // Alow or not to open menu after more then 1 ViewController into UINavigationController's stack list of VCs
    public static var openMenuOnlyFirstViewController: Bool = true

    // Status bar options
    public static var hideStatusBar: Bool = false
    public static var showsStatusBarBackground: Bool = false
    public static var statusBarBackgroundColor: UIColor = UIColor.clearColor()
}

然后您需要根据如下方式覆盖 SliderMenuViewController

import SlideMenuDovi

class YourRootViewController: SliderMenuViewController {

  override func viewDidLoad() {
      super.viewDidLoad()

      let main = YourMainViewController()
      let left = YourLeftViewController()
      let right = YourRightViewController()

      self.initPanel(main, leftMenuViewController: left, rightMenuViewController: right)
  }

  override func setupSlidingMenuOptions() {
        //Setup any SlideMenuOptions that you want to change inside this method
        SliderMenuOptions.animationDuration = 0.2
        SliderMenuOptions.statusBarBackgroundColor = UIColor.redColor()
    }
}

完成项目已设置 SlideMenu!!!

可用的动画

  1. 经典动画,主视图将滑动
SliderMenuOptions.animationType = SliderMenuAnimationDefault()

alt text

  1. Android 动画,左或右侧会滑动到中心视图上
SliderMenuOptions.animationType = SliderMenuAnimationSliderOver()

alt text

自定义动画

如果您对两个默认动画不满意,不要担心,家长在这里帮助您 :). 要创建自己的动画,您只需要实现一个 SliderMenuAnimation,该动画实现了 5 个协议(AnimatorCheckerAnimatorFireAnimatorGestureAnimatorVectorGlobalVariables)。

SliderMenuAnimationX

public class SliderMenuAnimationX: NSObject, SliderMenuAnimation {
    public var silderMenuGesture: SliderMenuGesture {
        get {
            return SliderMenuGestureDefault.sharedInstance
        }
    }

    /**
     *  Change the order of those views
     */
    public func orderList() {
        rootView.addSubview(self.menuViews.mainContainerView)
        rootView.addSubview(self.menuViews.opacityView)
        rootView.addSubview(self.menuViews.rightContainerView)
        rootView.addSubview(self.menuViews.leftContainerView)

        if SliderMenuOptions.showsStatusBarBackground {
            rootView.addSubview(self.menuViews.statusBarView)
        }

    }
}

如果您想覆盖任何协议,有 2 种方法

1 - 我没有时间

在 'AnimationType/SliderMenuAnimationX.swift' 中创建一个新文件。扩展 SliderMenuAnination 中的一个(可以是 SliderMenuAnimationDefaultSliderMenuAnimationSliderOver),并覆盖所需的所有方法。

public class SliderMenuAnimationX: NSObject, SliderMenuAnimation {
    public var silderMenuGesture: SliderMenuGesture {
        get {
            return SliderMenuGestureDefault.sharedInstance
        }
    }

    /**
     *  Change the order of those views
     */
    public func orderList() {
        self.rootView.addSubview(self.menuViews.mainContainerView)
        self.rootView.addSubview(self.menuViews.opacityView)
        self.rootView.addSubview(self.menuViews.rightContainerView)
        self.rootView.addSubview(self.menuViews.leftContainerView)

        if SliderMenuOptions.showsStatusBarBackground {
            self.rootView.addSubview(self.menuViews.statusBarView)
        }

    }

    public func isLeftSideOpen() -> Bool {
      // set the right result by using **GlobalVariables**'s methods (**SliderMenuAnimation** all ready implement **GlobalVariables**)
    }
}

2 - 我有时间

在 'AnimatorChecker/AnimatorCheckerX.swift' 中创建一个新文件,该文件将实现 AnimatorCheckerAnimatorCheckerSliderOver。您可以对其他协议做同样的事情(AnimatorFireAnimatorGestureAnimatorVectorGlobalVariables

public protocol AnimatorCheckerX: AnimatorChecker {}

extension AnimatorCheckerX {

  public func isLeftSideOpen() -> Bool {
    // set the right result by using **GlobalVariables**'s methods (**AnimatorChecker** all ready implement **GlobalVariables**)
  }

}

在 'AnimationType/SliderMenuAnimationX.swift' 中创建一个新文件。扩展 SliderMenuAnination 中的一个(可以是 SliderMenuAnimationDefaultSliderMenuAnimationSliderOver),并扩展新创建的协议 AnimatorCheckerX

public class SliderMenuAnimationX: NSObject, SliderMenuAnimation, AnimatorCheckerX {
    public var silderMenuGesture: SliderMenuGesture {
        get {
            return SliderMenuGestureDefault.sharedInstance
        }
    }

    /**
     *  Change the order of those views
     */
    public func orderList() {
        self.rootView.addSubview(self.menuViews.mainContainerView)
        self.rootView.addSubview(self.menuViews.opacityView)
        self.rootView.addSubview(self.menuViews.rightContainerView)
        self.rootView.addSubview(self.menuViews.leftContainerView)

        if SliderMenuOptions.showsStatusBarBackground {
            self.rootView.addSubview(self.menuViews.statusBarView)
        }
    }
}

您刚刚创建了自己的动画 :)

更多详情

AnimatorChecker

/**
 *  Check if menu is open or close
 */
public protocol AnimatorChecker: GlobalVariables {
    func isLeftSideOpen() -> Bool
    func isLeftSideHidden() -> Bool
    func isRightSideOpen() -> Bool
    func isRightSideHidden() -> Bool
}

AnimatorFire

/**
 *  It will fire the animation
 */
public protocol AnimatorFire: GlobalVariables {
    func toggleLeft()
    func toggleRight()

    func closeLeft()
    func closeRight()

    func openLeft()
    func openRight()

    func addShadowToView(targetContainerView: UIView)
    func removeShadow(targetContainerView: UIView)

    func animateLeftSideToOpen()
    func animateLeftSideToClose()
    func animateRightSideToOpen()
    func animateRightSideToClose()
}

AnimatorGesture

/**
 *  It will be call when the Pan gesture (left or right) is activated
 */
public protocol AnimatorGesture: GlobalVariables {
    func beganLeftTranslationGesture()
    func changedLeftTranslationGesture(frameTranslation: CGRect)
    func endLeftTranslationGesture(velocity: CGPoint) -> PanInfo

    func beganRightTranslationGesture()
    func changedRightTranslationGesture(frameTranslation: CGRect)
    func endRightTranslationGesture(velocity: CGPoint) -> PanInfo

    func applyLeftGestureTranslation(translation: CGPoint, toFrame:CGRect) -> CGRect
    func applyRightGestureTranslation(translation: CGPoint, toFrame:CGRect) -> CGRect
}

AnimatorVector

/**
 *  It will be call to close or open menu
 */
public protocol AnimatorVector: GlobalVariables {
    func resetAnimationLeftSide()
    func resetAnimationRightSide()
    func transitionToSize(transitionCoordinator: UIViewControllerTransitionCoordinator)

    func openLeftWithVelocity(velocity: CGFloat)
    func closeLeftWithVelocity(velocity: CGFloat)

    func openRightWithVelocity(velocity: CGFloat)
    func closeRightWithVelocity(velocity: CGFloat)
}

所有这些协议都实现了 全局变量,这将有助于您访问所需的所有信息。

/**
 *  Give you access to all you need
 */
public protocol GlobalVariables: class {
    var rootView: UIView { get }
    var menuTools: MenuTools { get }
    var menuViews: MenuViews { get }
    var menuViewControllers: MenuViewControllers { get }
    var animationType: SliderMenuAnimation { get }
    var gesture: SliderMenuGesture { get }
    var leftViewController: UIViewController? { get }
    var rightViewController: UIViewController? { get }
    var mainViewController: UIViewController? { get }
}

示例

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

要求

SlideMenuDovi 使用 swift 2.2

安装

SlideMenuDovi 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile

pod "SlideMenuDovi"

作者

Edouard Roussillon

许可证

SlideMenuDovi 采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。