ios - 如何在 Swift 中向 UIView 发送滑动动作
问题描述
我正在尝试克隆 Tinder,完成了 Yalantis/Koloda(https://github.com/Yalantis/Koloda)向左(不喜欢的人)和向右(喜欢的人)滑动的操作。我还有两个按钮喜欢/不喜欢的图像。我希望当我触摸喜欢/不喜欢的图像时,我的 mainView 会向左/向右滑动。
let likeImageTap = UITapGestureRecognizer(target: self, action: #selector(HomeViewController.sendSwipeRightAction))
likeImage.isUserInteractionEnabled = true
likeImage.addGestureRecognizer(likeImageTap)
我应该如何输入这个函数?
@objc func sendSwipeRightAction() {
}
这是我的协议
extension HomeViewController: KolodaViewDataSource, KolodaViewDelegate {
//...
func koloda(_ koloda: KolodaView, didSwipeCardAt index: Int, in direction: SwipeResultDirection)
{
if direction == .left {
//...
print ("swipe left")
}
if direction == .right {
//...
print("swipe right")
}
}
}
这是我的看法
@IBOutlet var mainView: KolodaView!
我尝试使用这个函数,然后在点击图像时调用它,这样我就可以像滑动一样做我想做的事情,但视图不会更改为下一张图像。
public func swipe(_ direction: SwipeResultDirection, force: Bool = false)
{
//..
}
所以我想向视图发送滑动动作,例如:
mainView.sendActions(for: .swipeLeft)
我应该怎么做?谢谢你的建议。
解决方案
示例中有代码
kolodaView.swipe(.left)
kolodaView.swipe(.right)
你的代码将是这样的
@objc func sendSwipeRightAction() {
mainView.swipe(.right)
}
推荐阅读
- amazon-web-services - 从 AWS S3 Presigned URL 强制下载 PDF
- python - 如何在 python-intercom 中通过自定义属性查找用户
- java - Intellij 上使用的字符不适用于 CMD
- php - wordpress 函数,PHP 未处理,显示为纯文本
- amazon-web-services - 无法删除 Amazon ECS 集群
- r - 在 R 中使用 coxph 进行时变协变量的生存分析
- php - 获取包含具有相同值的其他元素的多维数组中元素的索引并使用它来填充表单?
- java - Java String Switch 计票
- sql - SQL 使用 WHERE 从多个表中获取数据
- servlets - 了解 Jetty 的“待处理/未就绪时关闭”警告