azizuysal / AUPickerCell

Embedded picker view for table cells.
MIT License
19 stars 9 forks source link

Delete the right label when the picker is closed #4

Open SerDevMet opened 5 years ago

SerDevMet commented 5 years ago

Unless the Picker is closed, the data contained in the right labels of the cells below are deleted. Can you help me to resolve?

I changed this to the AUPickerCell.swift class to increase the height of the list when opening the picker:

public func selectedInTableView(_ tableView: UITableView) { let unexpandedHeightList = CGFloat(Double(tableView.numberOfRows(inSection: 0)) * 29.5) let expandedHeightList = unexpandedHeightList + picker.bounds.height let heightList = !self.expanded ? expandedHeightList : unexpandedHeightList print(heightList) let expandedFrame = CGRect(x: tableView.frame.origin.x, y: tableView.frame.origin.y, width: tableView.bounds.width, height: heightList) print(expandedFrame.height) if !expanded { rightLabelTextColor = rightLabel.textColor } expanded = !expanded UIView.transition(with: rightLabel, duration: 0.15, options: .transitionCrossDissolve , animations: { [unowned self] in tableView.frame = expandedFrame self.rightLabel.textColor = self.expanded ? self.tintColor : self.rightLabelTextColor }) tableView.beginUpdates() tableView.endUpdates() }

example

SerDevMet commented 5 years ago

RESOLVE:

public func selectedInTableView(_ tableView: UITableView) { tableView.beginUpdates() let unexpandedHeightList = CGFloat(Double(tableView.numberOfRows(inSection: 0)) * 29.5) let expandedHeightList = unexpandedHeightList + picker.bounds.height let heightList = !self.expanded ? expandedHeightList : unexpandedHeightList let expandedFrame = CGRect(x: tableView.frame.origin.x, y: tableView.frame.origin.y, width: tableView.bounds.width, height: heightList)

if !expanded {
  rightLabelTextColor = rightLabel.textColor
}
expanded = !expanded

UIView.transition(with: rightLabel, duration: 0.15, options: .transitionCrossDissolve , animations: { [unowned self] in
    self.rightLabel.textColor = self.expanded ? self.tintColor : self.rightLabelTextColor

})
UIView.transition(with: picker, duration: 0.30, options: .curveEaseInOut, animations: {
    tableView.frame = expandedFrame
})
tableView.endUpdates()

}