我正在尝试克隆 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)
我应该怎么做?谢谢你的建议。