Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

seepel

macrumors 6502
Original poster
Dec 22, 2009
471
1
I'm having the problem...

I would like to implement behavior similar to the iPad Music App where when you click on an album it animates the album flipping to reveal the track list. My case is slightly different as I would like to perform this from a UIView contained in a UIScrollView that may be zoomed to an arbitrary scale.

So I have a UIScrollView that contains a contentView that is larger than the UIScrollView. The contentView then contains multiple UIViews. The UIScrollView is set at some arbitrary scale. When the user clicks on one of the UIViews that UIView should appear to flip and reveal it's detail view. However, the detail view should be the same size independent of the zoom scale.

My current implementation is such that when a user clicks on a UIView, I add a containerView on top of the UIScrollView, copy an image of the UIView clicked on into the containerView. I then attempt to run transitionWithView to get the animation. The problem seems to be that since this containerView is created immediately before the animation call it doesn't seem to be animating the changes. It's as if I'm running into some problem with event loop timing. That because the container view doesn't exist at the beginning of the event loop everything happens all at once and nothing animates.

This is all very convoluted so here is the code that I call when a user taps on the view.

Code:
- (void)gestureDidTap:(UIGestureRecognizer *)gestureRecognizer {
    CGPoint location = [gestureRecognizer locationInView:self.contentView];
    for(UIView *view in self.contentView.subviews) {
        if(CGRectContainsPoint(view.frame, location)) {
            UIView *containerView = [[UIView alloc] initWithFrame:[self convertRect:view.frame fromView:self.contentView]];
            containerView.backgroundColor = [UIColor clearColor];

            UIGraphicsBeginImageContext(view.bounds.size);            
            [view.layer renderInContext:UIGraphicsGetCurrentContext()];
            UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();

            UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
            imageView.frame = CGRectMake(0, 0, containerView.frame.size.width, containerView.frame.size.height);
            [containerView addSubview:imageView];
            [self addSubview:containerView];
            UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 256, 256)];
            newView.backgroundColor = [UIColor whiteColor];
            [UIView transitionWithView:containerView
                              duration:1.0
                               options:UIViewAnimationOptionTransitionFlipFromLeft
                            animations:^(void) {
                                [imageView removeFromSuperview];
                                [containerView addSubview:newView];
                            }
                            completion:nil];
            [containerView release];
            [imageView release];
            break;
        }
    }
}

The problem with the code above is that it does not animate. The end result is correct but there is no animation. I've also verified that without adding the animation call the beginning state displays correctly. Has anyone ever encountered something similar to this before?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.