DraggableView
示例
要运行示例项目,请克隆仓库,然后首先从示例目录运行 pod install
安装
DraggableView 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中:
pod 'DraggableView'
用法
使用方法简单,就像创建一个基本的 UIView 的实例一样
var draggableView = DraggableView()
// The padding value that it will stay far from the edges
draggableView.padding = 16
// The threshold value defines the velocity on both x and y axis.
// After draging the view, the view will position itself according to
// the x and y velocity if the threshold condition is met.
// Othwerwise, it will position itself to the nearest corner.
// See the source code on how it positions itself.
draggableView.threshold = 1500
UIViewController 示例
import UIKit
import DraggableView
class CustomView: DraggableView {
// Your custom codes...
}
class ViewController: UIViewController {
let draggableView = CustomView()
override func viewDidLoad() {
super.viewDidLoad()
setDraggableView()
}
func setDraggableView() {
draggableView.translatesAutoresizingMaskIntoConstraints = false
draggableView.backgroundColor = .darkGray
view.addSubview(draggableView)
draggableView.padding = 10
draggableView.threshold = 1500
let screenSize = UIScreen.main.bounds
NSLayoutConstraint.activate([
draggableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: draggableView.padding),
draggableView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -draggableView.padding),
draggableView.heightAnchor.constraint(equalToConstant: screenSize.height * 0.4),
draggableView.widthAnchor.constraint(equalToConstant: screenSize.width * 0.5)
])
}
}
作者
korelhayrullah, [email protected]
许可
DraggableView 以 MIT 许可证提供。更多信息请参阅 LICENSE 文件。