我正在尝试使用MDCSwipeToChoose Delegate在Swift中执行“Tinder Swipe”。我正在关注本教程https://github.com/modocache/MDCSwipeToChoose
但是在安装CocoaPod并插入教程中的代码后,我得到错误“Type'ViewController'不符合协议'MDCSwipeToChooseDelegate'”。以下是我的ViewController中包含错误的部分代码:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var options = MDCSwipeToChooseViewOptions() // Here is where I get the error
options.delegate = self //And the same error here
options.likedText = "Keep"
options.likedColor = UIColor.blueColor()
options.nopeText = "Delete"
options.onPan = { state -> Void in
if state.thresholdRatio == 1 && state.direction == MDCSwipeDirection.Left {
println("Photo deleted!")
}
}
var view = MDCSwipeToChooseView(frame: self.view.bounds, options: options)
view.imageView.image = UIImage(named: "photo.png")
self.view.addSubview(view)
}
答案 0 :(得分:2)
您的ViewController应该实现MDCSwipeToChooseDelegate
协议。所以应该是这样的:
class ViewController: UIViewController, MDCSwipeToChooseDelegate {
你可能想要实现这个协议的方法(有可选的,但根据你想做什么,你可能不得不使用它们)
func viewDidCancelSwipe(view: UIView) -> Void
func view(view: UIView, shouldBeChosenWithDirection: MDCSwipeDirection) -> Bool
func view(view: UIView, wasChosenWithDirection: MDCSwipeDirection) -> Void
答案 1 :(得分:0)
您是否实施了所有必要的方法?
func viewDidCancelSwipe(view: UIView) -> Void
func view(view: UIView, shouldBeChosenWithDirection: MDCSwipeDirection) -> Bool
func view(view: UIView, wasChosenWithDirection: MDCSwipeDirection) -> Void