SideMenuKit 0.0.2

SideMenuKit 0.0.2

ghtienvv 维护。



  • 作者
  • ghtienvv

SideMenuKit

EasySideMenu 已移动并重命名为:SideMenuKit

Group 13428

要求

Swift 5.x, iOS 15+

安装

Cocoapods

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

pod 'SideMenuKit'

Swift 包管理器

  1. 文件 > Swift 包 > 添加包依赖
  2. 添加 https://github.com/tienvv88/SideMenuKit.git

或是

更新 Package.swift 中的 dependencies

dependencies: [.package(url: "[https://github.com/tienvv88/SideMenuKit.git]", .upToNextMajor(from: "0.1.10"))]

演示

侧面/样式 经典 3D 旋转(外部翻转) 3D 旋转(内部翻转) 中心剪裁 底部剪裁 顶部剪裁 向左倒 向右倒
左侧
右侧
两侧

示例

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

参数

init SMKView

参数 值类型 默认值
leftStyle SMKSide .classic
rightStyle SMKStyle .classic
animation 动画 .snappy(duration: 0.25, extraBounce: 0.1)
leftMenuWidth CGFloat UIScreen.main.bounds.width * 0.5
rightMenuWidth CGFloat UIScreen.main.bounds.width * 0.5
cornerRadius CGFloat 25
overlayColorWhenOpenMenu Color Color.black.opacity(0.3)
allowTapContentToCloseMenu Bool true
showLeftMenu 绑定 与左侧菜单或两侧菜单强制要求
showRightMenu 绑定 与右侧菜单或两侧菜单强制要求
allowSwipeToOpenMenu 绑定 .constant(true)
内容 View 强制要求
leftMenu View 与左侧菜单或两侧菜单强制要求
leftBackground View 可选
rightMenu View 与右侧菜单或两侧菜单强制要求
rightBackground View 可选

SMKStyle

样式 参数 值范围
经典 -- --
rotation3D - 翻转:SMKRotation3DStyle(flipOutside,flipInside)
- 旋转:CGFloat
旋转:0 -> 90
向右倒 -- --
向左倒 -- --
clipToCorner 边缘:SMKClipToCorner(top,bottom),offsetY offsetY:100 -> (UIScreen.main.bounds.width / 2)
中心剪裁 contentHeight:CGFloat contentHeight:(UIScreen.main.bounds.height / 3) -> UIScreen.main.bounds.height

使用

SwiftUI

左侧菜单

import SwiftUI
import SideMenuKit

struct SwiftUIRootView: View {

    @State private var isShowLeftMenu: Bool = false
    @State private var isShowRightMenu: Bool = false

    private var leftStyle: SMKStyle = .classic
    private var rightStyle: SMKStyle = .classic

    var body: some View {
        LeftMenu()
    }

    @ViewBuilder
    private func LeftMenu() -> some View {
        SKMView(
            leftStyle: leftStyle,
            showLeftMenu: $isShowLeftMenu,
            content: {
                MainView(showLeftMenu: $isShowLeftMenu,
                         showRightMenu: $isShowRightMenu,
                         showLeftMenuIcon: true,
                         showRightMenuIcon: false)
            },
            leftMenu: {
                LeftMenuView()
            },
            leftBackground: {
                Rectangle()
                    .fill(Color.black.opacity(0.8))
            }
        )
    }
}

#Preview {
    SwiftUIRootView()
}

右侧菜单

import SwiftUI
import SideMenuKit

struct SwiftUIRootView: View {

    @State private var isShowLeftMenu: Bool = false
    @State private var isShowRightMenu: Bool = false

    private var leftStyle: SMKStyle = .classic
    private var rightStyle: SMKStyle = .classic

    var body: some View {
        RightMenu()
    }

    @ViewBuilder
    private func RightMenu() -> some View {
        SKMView(
            rightStyle: rightStyle,
            rightMenuWidth: 100,
            showRightMenu: $isShowRightMenu,
            content: {
                MainView(showLeftMenu: $isShowLeftMenu,
                         showRightMenu: $isShowRightMenu,
                         showLeftMenuIcon: false,
                         showRightMenuIcon: true)
            },
            rightMenu: {
                RightMenuView(style: rightStyle)
            },
            rightBackground: {
                Rectangle()
                    .fill(Color.black.opacity(0.8))
            }
        )
    }
}

#Preview {
    SwiftUIRootView()
}

两侧菜单

import SwiftUI
import SideMenuKit

struct SwiftUIRootView: View {

    @State private var isShowLeftMenu: Bool = false
    @State private var isShowRightMenu: Bool = false

    private var leftStyle: SMKStyle = .classic
    private var rightStyle: SMKStyle = .classic

    var body: some View {
        BothMenu()
    }

    @ViewBuilder
    private func BothMenu() -> some View {
        SKMView(
            leftStyle: leftStyle,
            rightStyle: rightStyle,
            rightMenuWidth: 100,
            showLeftMenu: $isShowLeftMenu,
            showRightMenu: $isShowRightMenu,
            content: {
                MainView(showLeftMenu: $isShowLeftMenu,
                         showRightMenu: $isShowRightMenu,
                         showLeftMenuIcon: true,
                         showRightMenuIcon: true)
            },
            leftMenu: {
                LeftMenuView()
            },
            leftBackground: {
                Rectangle()
                    .fill(Color.black.opacity(0.8))
            },
            rightMenu: {
                RightMenuView(style: rightStyle)
            }, rightBackground: {
                Rectangle()
                    .fill(Color.black.opacity(0.8))
            }
        )
    }
}

#Preview {
    SwiftUIRootView()
}

贡献

我们始终欢迎社区的贡献。要修改项目,您可以克隆仓库并打开 Package.swift。此包包括

  • Sources/SideMenuKit/SMKEntity.swift
  • Sources/SideMenuKit/SMKView.swift
  • Sources/SideMenuKit/SMKView+UI.swift
  • Sources/SideMenuKit/SMKView+Calculator.swift
  • Sources/SideMenuKit/SMKView+Control.swift
  • Sources/SideMenuKit/SMKView+Gesture.swift

请彻底测试所有更改并创建一个根据模板的 MR,我们将尽快审查它。

作者

tienvv88, [email protected]

许可证

SideMenuKit 可在 MIT 许可证下获得。有关更多信息,请参阅 LICENSE 文件。