YALSideMenu 2.0.1

YALSideMenu 2.0.1

测试测试
Lang语言 SwiftSwift
许可 MIT
发布最新发布2016年10月
SPM支持 SPM

Maksim UsenkoSerhii Butenko 维护。




侧边菜单

具有可自定义 UI 的动画侧边菜单。由 Yalantis 制作。
查看这个 dribbble 项目
查看这个 Behance 项目

要求

  • iOS 7.x / 8.x / 9.x(请参阅安装说明)
  • Swift 3
  • Xcode 8

安装

手动安装

对于不支持嵌入框架的应用程序目标,例如 iOS 7,可以通过包含 SideMenu 文件夹中的源文件直接集成 SideMenu。是的,这很糟糕。

  1. 通过在终端中打开,在您的顶级项目目录中运行 cd 命令,并输入以下命令将 SideMenu 添加为 子模块git submodule add https://github.com/yalantis/Side-Menu.iOS.git
  2. 打开 SideMenu 文件夹,并将 SideMenu.xcodeproj 拖到您的应用程序项目的文件导航器中。
  3. 在 Xcode 中,通过单击蓝色项目图标,然后在侧栏的“目标”标题下选择应用程序目标来导航到目标配置窗口。
  4. 请确保 SideMenu.framework 的部署目标与应用程序目标相匹配。
  5. 在窗口顶部的选项卡栏中,打开“构建阶段”面板。
  6. 展开“目标依赖项”组,并添加 SideMenu.framework
  7. 展开“链接二进制与库”组,并添加 SideMenu.framework
  8. 单击面板左上角的加号按钮,并选择“新建复制文件阶段”。将此新阶段重命名为“复制框架”,将“目标”设置为“框架”,并添加 SideMenu.framework

用法

  1. 导入 SideMenu 模块

    import SideMenu
  2. 在您的菜单视图控制器中采用 Menu 协议,例如

    class MyFancyMenuViewController: UIViewController, Menu  {
        @IBOutlet var menuItems = [UIView] ()
    }
  3. 在菜单视图控制器中设置 preferredContentSize 以指定所需的菜单宽度

  4. 在内容视图控制器中存储一个将动画我们的菜单的动画器。

    import SideMenu
    class ContentViewController: UIViewController  {
        var menuAnimator : MenuTransitionAnimator!
    }
  5. 使用参数初始化一个用于显示的动画器

    menuAnimator = MenuTransitionAnimator(mode: .presentation, shouldPassEventsOutsideMenu: false) { [unowned self] in
        self.dismiss(animated: true, completion: nil)
    }

    例如,如果您希望在点击菜单外部时隐藏菜单,您应该将 ‘shouldPassEventsOutsideMenu’ 标志传递为 ‘false’ 并分配一个 ‘tappedOutsideHandler’。实际上,当发生点击菜单外部事件时,您可以自由地执行任何您想做的事情,或者如果您想访问您的内容视图控制器,只需传递 ‘true’ 并将 ‘tappedOutsideHandler’ 设置为 nil。

  6. 实现 UIViewControllerTransitioningDelegate 类,该方法将返回我们的菜单动画器(MenuAnimator),并将其分配给菜单视图控制器的 transitioningDelegate(不要忘记设置 .Custom modal presentation style)。要隐藏菜单,您应该在 animationControllerForDismissedController 方法中返回 MenuTransitionAnimator(mode: .Dismissal)。

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let menu = segue.destination as! MenuViewController
        menu.transitioningDelegate = self
        menu.modalPresentationStyle = .custom
    }
    
    func animationController(forPresented presented: UIViewController, presenting _: UIViewController,
        source _: UIViewController) -> UIViewControllerAnimatedTransitioning? {
            return menuAnimator
    }
    
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return MenuTransitionAnimator(mode: .dismissal)
    }

请告诉我们!

如果您能提供包含我们组件项目的链接,我们将非常高兴。请将电子邮件发送至 [email protected]。如果您对动画有任何问题或建议,也请告诉我们。

提示:我们将发布更多精彩代码和关于如何制作比更好的 iOS(Android)用户界面的教程。敬请关注!

许可证

The MIT License (MIT)

Copyright © 2016 Yalantis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.