如果您想要创建除了当前动画之外的特殊动画,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!!!
SliderMenuOptions.animationType = SliderMenuAnimationDefault()
SliderMenuOptions.animationType = SliderMenuAnimationSliderOver()
如果您对两个默认动画不满意,不要担心,家长在这里帮助您 :). 要创建自己的动画,您只需要实现一个 SliderMenuAnimation,该动画实现了 5 个协议(AnimatorChecker、AnimatorFire、AnimatorGesture、AnimatorVector、GlobalVariables)。
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 种方法
在 'AnimationType/SliderMenuAnimationX.swift' 中创建一个新文件。扩展 SliderMenuAnination 中的一个(可以是 SliderMenuAnimationDefault 或 SliderMenuAnimationSliderOver),并覆盖所需的所有方法。
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**)
}
}
在 'AnimatorChecker/AnimatorCheckerX.swift' 中创建一个新文件,该文件将实现 AnimatorChecker 或 AnimatorCheckerSliderOver。您可以对其他协议做同样的事情(AnimatorFire、AnimatorGesture、AnimatorVector、GlobalVariables)
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 中的一个(可以是 SliderMenuAnimationDefault 或 SliderMenuAnimationSliderOver),并扩展新创建的协议 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 文件。