1

I am trying animation, where the UITableView is already in place,but the subview (which itself contains the cell's content view) for each of the UITableViewCells is outside the window bounds. It is outside the screen. When the view loads, the cell animate from left to right, one by one, till the rightmost x value of the frame touches the rightmost x value of the UITableView.

The animation is such that, once first cell takes off, the second cell takes off before the first cell is finished with it's animation. Similarly, the third cell takes off before the second is finished with it's animation. However, i am not able to achieve this, and i all my rows animate all-together.

-(void)animateStatusViewCells:(SupportTableViewCell *)cell
{
__block CGPoint center;
[UIView animateWithDuration:0.55 delay:0.55 options:UIViewAnimationOptionCurveEaseIn animations:^{
    center = cell.statusView.center;
    center.x += (cell.frame.size.width - 20);
    cell.statusView.center = center;
}completion:^(BOOL success){
    NSLog(@"Translation successful!!!");
    double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        //[self animateStatusViewCells:cell];
    });
}];
}


 -(void)animateSupportTableView:(UITableView *)myTableView
 {
   NSMutableArray *cells = [[NSMutableArray alloc] init];
   NSInteger count = [myTableView numberOfRowsInSection:0];

 for (int i = 0; i < count; i++) {
    [cells addObject:[myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]];
}

for (SupportTableViewCell *cell in cells) {

    [self animateStatusViewCells:cell];
   }

}

-(void)viewDidAppear:(BOOL)animated{
   [super viewDidAppear:animated];
   [self animateSupportTableView:_statusTableView];
 }

Here's the initWithStyle method for the custom UITableViewCell:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
 {
 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
 if (self) {
    // Initialization code
    _statusView = [[UIView alloc] initWithFrame:self.frame];
    self.contentView.backgroundColor = [UIColor greenColor];
    self.contentView.alpha = 0.7;
    CGPoint cellCenter = self.center;
    cellCenter.x = self.center.x -  (self.frame.size.width - 20);
    _statusView.center = cellCenter;

    [self addSubview:_statusView];
    [_statusView addSubview:self.contentView];
 }
 return self;

}

jerry
  • 274
  • 2
  • 19

3 Answers3

4

You need to use a different delay value for each animation. Instead of using a constant delay of .55, pass in the cell number to your animate method, and use something like:

CGFloat delay = .55 + cellNumber * cellDelay;
[UIView animateWithDuration: 0.55 delay: delay options:UIViewAnimationOptionCurveEaseIn animations:
^{
  //animation code
}
];
Duncan C
  • 128,072
  • 22
  • 173
  • 272
2

For what its worth, this is a clean solution:

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell,     forRowAtIndexPath indexPath: NSIndexPath) {
    let trans = CATransform3DMakeTranslation(-cell.frame.size.width, 0.0, 0.0)
    cell.layer.transform = trans

    UIView.beginAnimations("Move", context: nil)
    UIView.setAnimationDuration(0.3)
    UIView.setAnimationDelay(0.1 * Double(indexPath.row))
    cell.layer.transform = CATransform3DIdentity
    UIView.commitAnimations()
}
0

try this

declare this somewhere.

int c=0;


-(void)animateStatusViewCells:(SupportTableViewCell *)cell
{
__block CGPoint center;
[UIView animateWithDuration:0.55 delay:0.55 options:UIViewAnimationOptionCurveEaseIn animations:^{
    center = cell.statusView.center;
    center.x += (cell.frame.size.width - 20);
    cell.statusView.center = center;
}completion:^(BOOL success){
c++;
if(c<[cells count]){
[self animateStatusViewCells:[cells objectAtIndex:c]];
}
}];
}



-(void)animateSupportTableView:(UITableView *)myTableView
 {
   NSMutableArray *cells = [[NSMutableArray alloc] init];
   NSInteger count = [myTableView numberOfRowsInSection:0];

 for (int i = 0; i < count; i++) {
    [cells addObject:[myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]];
}

   [self animateStatusViewCells:[cells objectAtIndex:c]];


}
BhushanVU
  • 3,455
  • 1
  • 24
  • 33