UIPangestureRecognizer

UIPangestureRecognizer

现在,我正在开发一个iOS应用程序,该应用程序使用UITableviewCell的子类,该子类使用UIPanGestureRecognizer左右滑动,但收藏夹表视图细胞无法正常工作且出现错误。


  错误:致命错误:不支持NSCoding


UITableViewCell.swift

class FavoritesTableViewCell: UITableViewCell {

@IBOutlet weak var favimage: UIImageView!

@IBOutlet weak var texten: UILabel!

@IBOutlet weak var textfn: UILabel!

@IBOutlet weak var price: UILabel!

@IBOutlet weak var likeimage: UIImageView!

var originalCenter = CGPoint()
var deleteOnDragRelease = false
    override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    // Configure the view for the selected state
}

required init(coder aDecoder: NSCoder) {
    fatalError("NSCoding not supported")
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    let recognizer = UIPanGestureRecognizer (target: self, action: "handlePan:")
    recognizer.delegate = self
    addGestureRecognizer(recognizer)
        }
//MARK: - horizontal pan gesture methods
func handlePan(recognizer: UIPanGestureRecognizer) {
    // 1
    if recognizer.state == .Began {
        // when the gesture begins, record the current center location
        originalCenter = center
    }
    // 2
    if recognizer.state == .Changed {
        let translation = recognizer.translationInView(self)
        center = CGPointMake(originalCenter.x + translation.x, originalCenter.y)
        // has the user dragged the item far enough to initiate a delete/complete?
        deleteOnDragRelease = frame.origin.x < -frame.size.width / 2.0
    }
    // 3
    if recognizer.state == .Ended {
        // the frame this cell had before user dragged it
        let originalFrame = CGRect(x: 0, y: frame.origin.y,
                                   width: bounds.size.width, height: bounds.size.height)
        if !deleteOnDragRelease {
            // if the item is not being deleted, snap back to the original location
            UIView.animateWithDuration(0.2, animations: {self.frame = originalFrame})
        }
    }
}

override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
    if let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {
        let translation = panGestureRecognizer.translationInView(superview!)
        if fabs(translation.x) > fabs(translation.y) {
            return true
        }
        return false
    }
    return false
}}


and my favourite storyboard

最佳答案

评论或删除此内容:

required init(coder aDecoder: NSCoder) {
    fatalError("NSCoding not supported")
}

关于ios - UIPanGestureRecognizer右和左tableviewcell,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39684047/

10-12 00:04