Я играю вокруг, пытаясь одушевить содержимое моей таблицы, когда оно выбрано, но у меня проблемы. Я прочитал несколько мест, в которых вы не можете запустить animatewithduration в файле didSelectRowAtIndexPath или, по крайней мере, он не оживляет, если вы это сделаете. Это похоже на код, который у меня ниже, представление движется, но не оживляет.Swift - Анимация, когда выбран TableView Cell (didSelectRowAtIndexPath)
Я попытался включить логику в willDisplayCell для контроля за выбором, но безрезультатно, и поэтому мне бы это понравилось, если кто-то сможет найти для меня правильное решение, потому что ответ, похоже, недоступен, несмотря на много исп.:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let currentCellDescriptor = getCellDescriptorForIndexPath(indexPath)
let cell = tableView.dequeueReusableCellWithIdentifier(currentCellDescriptor["cellIdentifier"] as! String, forIndexPath: indexPath) as! CustomCell
let indexOfTappedRow = visibleRowsPerSection[indexPath.section][indexPath.row]
if cellDescriptors[indexPath.section][indexOfTappedRow]["isExpandable"] as! Bool == true {
if cellDescriptors[indexPath.section][indexOfTappedRow]["isExpanded"] as! Bool == false {
// INTERESTING BIT: Animates cell contents to Right
if currentCellDescriptor["cellIdentifier"] as! String == "CellHeader" {
UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 12, options: .CurveLinear, animations: {
cell.headerTitleLeftConstraint.priority = 999
cell.headerTitleRightConstraint.priority = 1
cell.layoutIfNeeded()
}, completion: nil)
}
} else if cellDescriptors[indexPath.section][indexOfTappedRow]["isExpanded"] as! Bool == true {
// MARK: Animates cell contents back to left
if currentCellDescriptor["cellIdentifier"] as! String == "CellHeader" {
UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 12, options: .CurveLinear, animations: {
cell.headerTitleLeftConstraint.priority = 1
cell.headerTitleRightConstraint.priority = 999
cell.layoutIfNeeded()
}, completion: nil)
}
}
Почему вы используете «пусть клетка = tableView.dequeueReusableCellWithIdentifier (currentCellDescriptor [ "cellIdentifier"], как String, forIndexPath: indexPath) как! CustomCell 'в' didSelectRowAtIndexPath '? – MrDank
Г-н Вейдер, это потому, что у меня есть plist, который содержит все данные моей ячейки. Это намного проще, потому что у меня есть несколько расширяемых уровней ячеек. –