Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions ExpandingStackCells/Data/SimpleItemStore.swift
Expand Up @@ -14,6 +14,16 @@ struct SimpleItemStore {
SimpleItem(title: "A really long item title for testing self-sizing mechanism", detail: "A really long detail title to test self-sizing mechanism"),
SimpleItem(title: "Item 1", detail: "Detail 1"),
SimpleItem(title: "Item 2", detail: "Detail 2"),

SimpleItem(title: "A really long item title for testing self-sizing mechanism", detail: "A really long detail title to test self-sizing mechanism"),
SimpleItem(title: "Item 1", detail: "Detail 1"),
SimpleItem(title: "Item 2", detail: "Detail 2"),
SimpleItem(title: "A really long item title for testing self-sizing mechanism", detail: "A really long detail title to test self-sizing mechanism"),
SimpleItem(title: "Item 1", detail: "Detail 1"),
SimpleItem(title: "Item 2", detail: "Detail 2"),
SimpleItem(title: "A really long item title for testing self-sizing mechanism", detail: "A really long detail title to test self-sizing mechanism"),
SimpleItem(title: "Item 1", detail: "Detail 1"),
SimpleItem(title: "Item 2", detail: "Detail 2"),
]
}
}
Expand Up @@ -44,9 +44,10 @@ class MainViewController: UITableViewController {
override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {

if let selectedIndex = tableView.indexPathForSelectedRow where selectedIndex == indexPath {

let cell = tableView.cellForRowAtIndexPath(selectedIndex) as! ExpandingCell
tableView.beginUpdates()
tableView.deselectRowAtIndexPath(indexPath, animated: true)
cell.changeCellStatus(false)
tableView.endUpdates()

return nil
Expand All @@ -56,6 +57,8 @@ class MainViewController: UITableViewController {
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath) as! ExpandingCell
cell.changeCellStatus(true)
tableView.beginUpdates()
tableView.endUpdates()
}
Expand Down
34 changes: 23 additions & 11 deletions ExpandingStackCells/Views/ExpandingCell.swift
Expand Up @@ -31,18 +31,30 @@ class ExpandingCell: UITableViewCell {
stackView.arrangedSubviews.last?.hidden = true
}

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

super.setSelected(selected, animated: animated)

// override func setSelected(selected: Bool, animated: Bool) {
//
// super.setSelected(selected, animated: animated)
//
// UIView.animateWithDuration(0.5,
// delay: 0,
// usingSpringWithDamping: 1,
// initialSpringVelocity: 1,
// options: UIViewAnimationOptions.CurveEaseIn,
// animations: { () -> Void in
// self.stackView.arrangedSubviews.last?.hidden = !selected
// },
// completion: nil)
// }

func changeCellStatus(selected: Bool){
UIView.animateWithDuration(0.5,
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 1,
options: UIViewAnimationOptions.CurveEaseIn,
animations: { () -> Void in
stackView.arrangedSubviews.last?.hidden = !selected
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 1,
options: UIViewAnimationOptions.CurveEaseIn,
animations: { () -> Void in
self.stackView.arrangedSubviews.last?.hidden = !selected
},
completion: nil)
completion: nil)
}
}