动画高度时点击手势没有响应
tap gesture not responding while animating height
我正在玩点按手势来为 UIView 的高度设置动画,我想要实现的是打开关闭或做一些下拉。如果我不使用 if else 语句,我的点击手势会起作用。但反过来不行。这是我的代码。
class DailyAbsenceCell: UICollectionViewCell {
@IBOutlet weak var mainContainer: UIView!
@IBOutlet weak var calendarView: JKCalendar!
@IBOutlet weak var mainContainerHeightConstraint: NSLayoutConstraint!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap))
mainContainer.addGestureRecognizer(tapGesture)
mainContainerHeightConstraint.constant = 75
calendarView.alpha = 0
}
@objc func handleTap(gesture: UITapGestureRecognizer) {
if gesture.state == .changed {
mainContainerHeightConstraint.constant = 370
calendarView.alpha = 1
print("Tapped")
} else {
mainContainerHeightConstraint.constant = 75
calendarView.alpha = 0
}
}
}
谢谢!!
if gesture.state == .changed
永远不会是真的。点击手势识别器没有改变的状态。事实上根本不需要检查它的状态。
将此更改为
if mainContainerHeightConstraint.constant == 75
我正在玩点按手势来为 UIView 的高度设置动画,我想要实现的是打开关闭或做一些下拉。如果我不使用 if else 语句,我的点击手势会起作用。但反过来不行。这是我的代码。
class DailyAbsenceCell: UICollectionViewCell {
@IBOutlet weak var mainContainer: UIView!
@IBOutlet weak var calendarView: JKCalendar!
@IBOutlet weak var mainContainerHeightConstraint: NSLayoutConstraint!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap))
mainContainer.addGestureRecognizer(tapGesture)
mainContainerHeightConstraint.constant = 75
calendarView.alpha = 0
}
@objc func handleTap(gesture: UITapGestureRecognizer) {
if gesture.state == .changed {
mainContainerHeightConstraint.constant = 370
calendarView.alpha = 1
print("Tapped")
} else {
mainContainerHeightConstraint.constant = 75
calendarView.alpha = 0
}
}
}
谢谢!!
if gesture.state == .changed
永远不会是真的。点击手势识别器没有改变的状态。事实上根本不需要检查它的状态。
将此更改为
if mainContainerHeightConstraint.constant == 75