测试测试 | ✗ |
Lang语言 | SwiftSwift |
许可 | MIT |
发布最新发布 | 2016年10月 |
SPM支持 SPM | ✗ |
由 Maksim Usenko,Serhii Butenko 维护。
具有可自定义 UI 的动画侧边菜单。由 Yalantis 制作。
查看这个 dribbble 项目。
查看这个 Behance 项目。
对于不支持嵌入框架的应用程序目标,例如 iOS 7,可以通过包含 SideMenu 文件夹中的源文件直接集成 SideMenu。是的,这很糟糕。
cd
命令,并输入以下命令将 SideMenu 添加为 子模块:git submodule add https://github.com/yalantis/Side-Menu.iOS.git
SideMenu
文件夹,并将 SideMenu.xcodeproj
拖到您的应用程序项目的文件导航器中。SideMenu.framework
的部署目标与应用程序目标相匹配。SideMenu.framework
。SideMenu.framework
SideMenu.framework
。导入 SideMenu
模块
import SideMenu
在您的菜单视图控制器中采用 Menu
协议,例如
class MyFancyMenuViewController: UIViewController, Menu {
@IBOutlet var menuItems = [UIView] ()
}
在菜单视图控制器中设置 preferredContentSize
以指定所需的菜单宽度
在内容视图控制器中存储一个将动画我们的菜单的动画器。
import SideMenu
class ContentViewController: UIViewController {
var menuAnimator : MenuTransitionAnimator!
}
使用参数初始化一个用于显示的动画器
menuAnimator = MenuTransitionAnimator(mode: .presentation, shouldPassEventsOutsideMenu: false) { [unowned self] in
self.dismiss(animated: true, completion: nil)
}
例如,如果您希望在点击菜单外部时隐藏菜单,您应该将 ‘shouldPassEventsOutsideMenu’ 标志传递为 ‘false’ 并分配一个 ‘tappedOutsideHandler’。实际上,当发生点击菜单外部事件时,您可以自由地执行任何您想做的事情,或者如果您想访问您的内容视图控制器,只需传递 ‘true’ 并将 ‘tappedOutsideHandler’ 设置为 nil。
实现 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.