长按上下文菜单
关于
手机屏幕的空间比桌面更有限。在设计应用程序界面时必须小心布局,以创建符合人体工程学的决策。在某些情况下,我们有一些没有主操作的多操作按钮。将所有按钮放到界面或将它们隐藏在模态视图中可能是不正确的行为。我们设计了长按上下文菜单,在手机屏幕上长按即可打开。设计在 Dribble
👍 项目,不要忘记⭐️ 我
关注最新更新 关注我🤙
如果你要求
- iOS 12.2+
- Xcode 11+
- Swift 5.0+
功能
本仓库包含2种布局,后续将添加更多
- 全自定义
- 自动计算交叉
- 欢迎更多贡献
🙌
示例
首先克隆仓库,然后在根目录下运行carthage update
。示例应用是查看EKLongPress
使用的最佳方式。只需打开EKLongPress.xcodeproj
并运行Example
方案。
安装
CocoaPods
EKLayout通过CocoaPods可用。要安装它,只需将以下行添加到您的Podfile
pod 'EKLongPress'
Carthage
Carthage是一种去中心化的依赖管理器,它构建您的依赖项并为您提供二进制框架。
要使用Carthage将EKLongPress
集成到您的Xcode项目中,请在您的Cartfile
中指定它
github "ekamalov/EKLongPress"
运行carthage update
来构建框架,并将构建的EKLongPress.framework
拖放到您的Xcode项目中。
在您的应用程序目标的“构建阶段”设置选项卡中,点击“+”图标并选择“新运行脚本阶段”,然后添加Carthage入门步骤4、5和6中提到的框架路径
手动
如果你不希望使用上述任何依赖管理器,你可以手动将 EKLongPress
整合到你的项目中。只需将 Sources
目录拖放到你的 Xcode 项目中即可。
用法
安装库并导入模块 EKLongPress
后,文本框可以像任何其他文本框一样使用。 ContextMenu
初始化器
/// - Parameter items: Items
/// - Parameter aling: To position relative to the ability to specify alignment. The items can be layouted relative to one or many comparable views.
/// - Parameter preference: Preference used to customize the appearance
/// - Parameter selectedItem: Close if selected item
/// - Parameter debug: For developer
public init(items: [EKItem], aling:ItemsAling = .center, preference: Preference = .init(),
selectedItem: ((_ item:EKItem) -> Void)? , debug:Bool = false) {
}
初始化器 EKItem
/// - Parameter title: Title of the item
/// - Parameter icon: Icon of the iten
/// - Parameter preference: Item appearance
public init(title: String, icon: UIImage, preference: Preference.ContextMenu.Item) {
}
使用
/// Example
// First needed to create an array of type EKItem you desire to show.
// For each item, you can create your appearance setting
let items: [EKItem] = [ EKItem.init(title:"Save", icon: #imageLiteral(resourceName: "add")),
EKItem.init(title:"Watch Trailer", icon: #imageLiteral(resourceName: "play")),
EKItem.init(title:"Share", icon: #imageLiteral(resourceName: "share")),
EKItem.init(title:"More", icon: #imageLiteral(resourceName: "more"))]
var cons = EKContextMenu(items: items, aling: .center, selectedItem: nil, debug: false)
view.addGestureRecognizer(cons.buildGesture()) // to add gesture call buildGesture method
如果你想要更改外观样式,可以查看下面的 Customizing
标题或以下部分
let items: [EKItem] = [ EKItem.init(title:"Save", icon: #imageLiteral(resourceName: "add")),
EKItem.init(title:"Watch Trailer", icon: #imageLiteral(resourceName: "play")),
EKItem.init(title:"Share", icon: #imageLiteral(resourceName: "share")),
EKItem.init(title:"More", icon: #imageLiteral(resourceName: "more"))]
var cons = EKContextMenu(items: items, aling: .center, selectedItem: nil, debug: false)
var preference = Preference.init()
preference.menu.titleFont = Fonts.GilroyBold.withSize(48)
cons.setAppearance(preference: preference)
view.addGestureRecognizer(cons.buildGesture()) // to add gesture call buildGesture method
定制
为了定制 EKLongPress
的外观和行为,你可以配置封装所有可定制属性的 Preferences
结构。这些首选项已经分成三个结构
基本
包含可定制属性,指定如何将 EKLongPress
在屏幕上绘制。请参阅默认值
/// Use the backgroundColor property to change the color of the context menu backgroundColor. By default, uses white with alpha 0.9
public var backgroundColor: UIColor = UIColor.black.withAlphaComponent(0.9)
/// Use the itemsDistance property to change the distance of the items between. By default, uses 15px
public var itemsDistance:CGFloat = 15
/// Use the itemDistFromCenter property to change the distance from of the item to touch point. By default, uses 15px
public var itemDistFromCenter:CGFloat = 34
/// Use the titleFont property to change the font of the title font. By default user "Gilroy-SemiBold" with size 48
public var titleFont:UIFont = .systemFont(ofSize: 48)
/// Use the titleColor property to change the color of the title text. By default, uses white with alpha 0.9
public var titleColor:UIColor = .white
/// Use the titleDistance property to change the distance from of the item to title text. By default, uses 64px
public var titleDistance:CGFloat = 64
/// Use the marginOfScreen property to change tThe indent from the edge of the screen. By default, uses 20px
public var marginOfScreen:CGFloat = 20
触摸点
你可以使用自己的参数格式化 TouchPoint
。使用这些参数来获取你期望的样式。请参阅默认值
/// Use the color property to change the color of the touch point. By default, uses white with alpha 0.1
public var color: UIColor = UIColor.white.withAlphaComponent(0.1)
/// The size of the touch location view // default 44
public var size: CGFloat = 44
/// The size of the touch location view // default value 6
public var borderWidth:CGFloat = 6
条目
使用这个来获取你想要的风格。查看默认值
/// Use the backgroundColor property to change the color of the item background. By default, uses white with alpha 0.1
public var backgroundColor:ColotState = .init(active: .white,
inactive: .init(red: 28 / 255, green: 28 / 255, blue: 28 / 255, alpha: 1))
/// Use the iconColor property to change the color of the icon color. By default, uses white with alpha 0.1
public var iconColor:ColotState = .init(active: .black, inactive: .white)
/// Use the iconSize property to change the size of the icon. By default, user width: 24, height: 24
public var iconSize:CGSize = .init(width: 24, height: 24)
/// Use the size property to change the size of the item. By default, user 56
public var size: CGFloat = 56
贡献
非常欢迎您的贡献
许可
EKLongPress
在 MIT 许可下发布。查看 LICENSE.md 获取详细信息。
MIT License
Copyright (c) 2019 Erik Kamalov <[email protected]>
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.