UITableViewCell setHighlighted,setSelected" animateAlsidesideTransition"或类似的

时间:2016-04-20 08:41:49

标签: ios swift uitableview

我希望能够将自定义动画添加到 UITableViewCell 的子类,这些子类会覆盖以下方法:

override func setHighlighted(highlighted: Bool, animated: Bool) {

}

override func setSelected(selected: Bool, animated: Bool) {

}

匹配这些方法执行的默认动画的动画曲线和动画持续时间

换句话说,如何找到Apple提供的有关当前动画的信息。我需要这个来添加我自己的自定义动画,完全匹配默认动画

1 个答案:

答案 0 :(得分:2)

您可以在表格视图中继承自定义单元格。

在这里,我在Swift中创建了一个简单的例子,我在其中更改了单元格内标签的值:

import UIKit

class userTableViewCell: UITableViewCell {
@IBOutlet weak var userLabel: UILabel!

override func awakeFromNib() {
    super.awakeFromNib()
    self.highlighted = false
    self.userLabel.alpha = 0.0
    // Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    if selected {
        self.highlighted = true
    } else {
        self.highlighted = false
    }

    // Configure the view for the selected state
}

override var highlighted: Bool {
    get {
        return super.highlighted
    }
    set {
        if newValue {
            // you could put some animations here if you want
            UIView.animateWithDuration(0.7, delay: 1.0, options: .CurveEaseOut, animations: {
                self.userLabel.text = "select"
                self.userLabel.alpha = 1.0

                }, completion: { finished in
                print("select")
            })
        }
        else {
            self.userLabel.text = "unselect"
        }
        super.highlighted = newValue
    }
}

}

在故事板上你必须拥有什么: screenshot of Xcode storyboard