as a background, this question is related to this that I posted earlier: Trying to expand / collapse a UITableViewCell from a UIButton in a custom cell
To summarize, I have a UITableView with multiple user table cells. Each custom UITableViewCell has a text area and then a View More button. Essentially, each cell initially displays 3 lines of text, but when the user clicks the View More button, the cell should expand to the entire height of the text area. Pressing the button again will break the cell.
I think this is hard to imagine, so I made a short video here: http://dl.dropbox.com/u/762437/cell-animation.mov
(this is about a 3.5 MB file, so you don’t have to download it for so long). In the video, I show the cell performing the expand / collapse animation. When expanded, the View More button enlivens down. When you click on it again, it simply returns to its original position without animation. Edit: Sorry, I have to be more clear. UITableView correctly animates cells, I ask how to make the "Details" button, the animation is correct.
I have a U-turn / crash working (I did it right or wrong, that's another thing!), But the animation works as I expect. Expanding animation works, but does not collapse.
UITableViewCell IBAction, , " ". , NSMutableArray. "", .
tableView cellForRowAtIndexPath , , .
:
if([expandedRows containsObject:indexPath])
{
[cell.textLabel sizeToFitFixedWidth:cell.textLabel.frame.size.width];
CGFloat bottomYPos = cell.textLabel.frame.origin.y + cell.textLabel.frame.size.height;
CGRect buttonRect = cell.showAllButton.frame;
buttonRect.origin.y = bottomYPos;
[UIView animateWithDuration:0.3
delay:0.0
options: UIViewAnimationCurveLinear
animations:^{
cell.showAllButton.frame = buttonRect;
[cell.showAllButton setTitle:@"Close" forState:UIControlStateNormal];
}
completion:^(BOOL finished){
NSLog(@"Done 1!");
}];
}
else
{
CGRect buttonRect = cell.showAllButton.frame;
buttonRect.origin.y -= cell.frame.size.height - [[originalCellSizes objectAtIndex:indexPath.row] floatValue];
[UIView animateWithDuration:0.3
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{
cell.showAllButton.frame = buttonRect;
[cell.showAllButton setTitle:@"View More" forState:UIControlStateNormal];
}
completion:^(BOOL finished){
NSLog(@"Done! 2");
}];
}
, "else" if-else buttonRect Y, . , , .
!