我有一个自定义的内联日期选择器,它可以像 Apple 日历事件日期选择器一样展开和折叠。问题是我需要将日期选择器放在 UITableView 底部的 UITableViewCell 中,但是当它展开时,如果不手动向下 ScrollView ,您将无法看到选择器。对于类似的问题(如果 UITextField 低于键盘高度,则在编辑时 UITextField 会在键盘后面消失),我可以使用 beginEditing 和 endEditing 委托(delegate)函数中的动画来修复它:
let keyboardHeight: CGFloat = 216
UIView.animateWithDuration(0.25, delay: 0.25, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
self.view.frame = CGRectMake(0, (self.view.frame.origin.y - keyboardHeight), self.view.bounds.width, self.view.bounds.height)
}, completion: nil)
有谁知道类似的动画可以放置在 didSelectRowAtIndexPath 中,如果它是日期选择器,屏幕将通过向下滚动来调整以显示完整的日期选择器展开,然后当行被选中时它将调整回来不再选择 - 或者类似的东西?
- 我不确定已经存在展开/折叠日期选择器的动画这一事实是否会与此冲突,或者这是否只是动画发生的优先级问题。无论如何,我将在下面发布一些代码:
当在tableView中选择DatePicker时:
/**
Used to notify the DatePickerCell that it was selected. The DatePickerCell will then run its selection animation and expand or collapse.
*/
public func selectedInTableView() {
expanded = !expanded
UIView.transitionWithView(rightLabel, duration: 0.25, options:UIViewAnimationOptions.TransitionCrossDissolve, animations: { () -> Void in
self.rightLabel.textColor = self.expanded ? self.tintColor : self.rightLabelTextColor
}, completion: nil)
}
didSelectRowAtIndexPath 函数:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// Deselect automatically if the cell is a DatePickerCell.
let cell = self.tableView(tableView, cellForRowAtIndexPath: indexPath)
if (cell.isKindOfClass(DatePickerCell)) {
let datePickerTableViewCell = cell as! DatePickerCell
datePickerTableViewCell.selectedInTableView()
tableView.deselectRowAtIndexPath(indexPath, animated: true)
} else if(cell.isKindOfClass(PickerCell)) {
let pickerTableViewCell = cell as! PickerCell
pickerTableViewCell.selectedInTableView()
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
tableView.beginUpdates()
tableView.endUpdates()
}
最佳答案
我认为我想出了一个似乎可以根据需要工作的解决方案,我在调用 selectedInTablView()
之后在 didSelectRowAtIndexPath
委托(delegate)函数中编写了以下代码:
if(datePickerTableViewCell.isExpanded() && datePickerTableViewCell.datePicker == billDatePicker.datePicker) {
tableView.contentOffset = CGPoint(x: 0, y: self.view.frame.height + datePickerTableViewCell.datePickerHeight())
}
关于swift - 当自定义展开/折叠日期选择器位于表格 View 的底部单元格时,它会展开 View - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35120152/