Done. i put this code into
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
before return cell.
Frage
I have a UITableView
. I want to make animation when cell is loading in table. I make it like this.
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
CGRect tmpFrame;
CGRect originalFrame;
originalFrame = cell.frame;
tmpFrame = cell.frame;
tmpFrame = CGRectMake(0, -50, 320, 50);
cell.frame = tmpFrame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.0f];
[UIView setAnimationBeginsFromCurrentState:YES];
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 320, 1)];
separatorLineView.backgroundColor = [UIColor lightGrayColor];
[cell.contentView addSubview:separatorLineView];
cell.frame = originalFrame;
[UIView commitAnimations];
}
This code is working fine in iOS 6 (iPhone simulator 6) but it's not working in iOS 5.1 (iPhone simulator 5.1).
Lösung
Done. i put this code into
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
before return cell.
Andere Tipps
So I know you already have the solution, but I might recommend using the animation blocks unless you are making it compatible with older versions. Anyway if you are not this might offer a different way to write animations. I like doing it this way because I feel like I have more control over whats happening and less mess.
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if(!cell){
cell = [[UITableViewCell alloc]init];
}
CGRect movementFrame = cell.frame; // set the movement frame for modification
movementFrame.origin.y -= 50; //adjust only one variable instead of making a rect..
//Start your animation block.
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationCurveEaseOut
animations:^{
//Animation here
cell.frame = movementFrame; // Commit your changes basically
} completion:^(BOOL finished) {
//Completeion c
}];
So awesome! Take Care ^^
Edit
Went to test it, and realized I left out a crucial part. I apologize.. but this code does work and will do this animation its kind of interesting on a grouped table with a page full of sections.