1

I'm getting problem with this app, I'm doing an animations app using tableview. All the app is working properly when I'm scrolling the images are flipping but when I'm opening app the images are not flipping, please help me this is my first app? when i do scrolling the image flipping but i need to flip a image without doing any action(like scrolling/draging/touching on screen). i need to show the image flipping directly on the simulator when will i run code but i'm not getting that exactly

this is the code i'm trying to do in .h file - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { CATransform3D rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, .0, 0.5, 0.5); cell.contentView.layer.transform = rotation;

    CGFloat rotationAngleDegrees = 360;
    CGFloat rotationAngleRadians = rotationAngleDegrees * (M_PI/360);
    //CGPoint offsetPositioning = CGPointMake(200, 20);
    CATransform3D transform = CATransform3DIdentity;
    transform = CATransform3DRotate(transform, rotationAngleRadians, 0.0, 1.0, 0.0);
   // transform = CATransform3DTranslate(transform, offsetPositioning.x, offsetPositioning.y, 0.0);

    UIView *card = [cell contentView];
    card.layer.transform = transform;
    card.layer.opacity = 0.8;

    [UIView animateWithDuration:1.0 animations:^{card.layer.transform = CATransform3DIdentity;
        card.layer.opacity = 1;}];

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"RoyCard";

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cellImg=(UIImage *)[cell viewWithTag:101];
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.7f];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:cellImg cache:NO];
        //    [cell removeFromSuperview];
        [UIView commitAnimations];

    }

    [UIView animateWithDuration:1.0 animations:^{tableView.layer.transform = CATransform3DIdentity;
        tableView.layer.opacity = 1;}];
       return cell;
}
shivaRaju
  • 67
  • 9

2 Answers2

0

When you say opening the app, do you mean coming back to the app from background?

If yes, then you should follow this answer here. https://stackoverflow.com/a/5278108/1029360

Opening the app from background does not call the viewWillAppear method. You should listen to the notification as mentioned in that answer and invoke a table view reload when notified.

Community
  • 1
  • 1
Adithya
  • 4,545
  • 3
  • 25
  • 28
  • i mean when i'm running the code first time on the simulator,i need flip the images directly without doing any scrolling – shivaRaju Aug 30 '14 at 07:42
  • Did you try calling the image flipping method from your viewWillAppear or viewDidApppear method? – Adithya Aug 30 '14 at 07:48
  • Try moving the code that you have posted to tableView:willDisplayCell delegate method. – Adithya Aug 30 '14 at 08:03
0

If you are calling the flipping image animation from inside the method of - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath, just remove it from there. Write a separate method for it, and if possible, write that method as part of your subclassed UITableViewCell's method. Inside your - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath, just create the cell in it's default state.

What you need to do is, after your app loads, inside the viewDidAppear for the first time, you will have to get all the cells which are visible by the UITableView's method of - (NSArray *)visibleCells. This will return you all the cells which are currently visible. Then, for each cell you can call the image flipping method which you have written. After that, when the user scrolls your table view, you can make use of the methods like - (void)scrollViewDidScroll:(UIScrollView *)scrollView of UIScrollViewDelegate protocol depending upon your requirements. But for that you will have to set the delegate of your UITableView.

Prasad
  • 5,946
  • 3
  • 30
  • 36