views:

325

answers:

1

I'm using the PageControl project, which is on Apple's dev site. I've added a flip view to the project and an info icon to the top right of each view/page. For some reason, only the first page is able to animate the flipping. Page 2 on still shows the flipped page but does not animate. To make sure it isn't anything special about page 1, I switch page 1 and 2 and that worked fine. Page 2 in position 1 animated while Page 1 in position 2 did not. Any ideas why this would happen or how I can trouble shoot it?

I did take a look at this thread, which seems to be the same issue: http://stackoverflow.com/questions/843534/flip-view-iphone. However, My flipview is a UIViewController and so is the class with the info icon on it. In the other thread, they are using UIViews.

I did implement the showInfo code from the above thread. When on Page 2, I see no flip. Then I scroll over to Page 1 and see it has flipped. Not sure why it isn't staying with Page 2. When on Page 1, it doesn't animate the flip. The flipview just suddenly appears.

+1  A: 

Do you have a containerView? Something that can be there so you can add and remove subviews from it? Animation can break if you have two viewControllers, one coming and one going, without a containerView. I use a rootViewController and animate all my pages to and from each other with the rootViewcontroller in the back. Here is my code for flipping, you'll probably have to do a little editing to make it work for you:

(keep in mind that self is the rootViewcontroller, a viewcontroller with a blank view (color it so it matches your views))

- (void)switchTwoViews:(UIViewController *)view1 otherView:(UIViewController *)view2
{
    /*
     This method is called to switch views.
     It flips the displayed view from the main view to the flipside view and vice-versa.
     */

    UIViewController *coming = nil;
    UIViewController *going = nil;
    UIViewAnimationTransition transition;

    [view1.view setUserInteractionEnabled: NO];
    [view2.view setUserInteractionEnabled: NO];
    if (view1.view.superview == nil) {
     coming = view1;
     going = view2;
     transition = UIViewAnimationTransitionFlipFromLeft;
    }
    else {
     coming = view2;
     going = view1;
     transition = UIViewAnimationTransitionFlipFromRight;
    }
        // in some cases the following is needed to size the view
    // coming.view.frame = [UIScreen mainScreen].applicationFrame;

    // going.view.alpha = 1.0;  //uncomment these lines if we want fading of views
    // coming.view.alpha = 0.0;

    NSArray *viewArray = [[NSArray alloc] initWithObjects:coming, going, nil];
    [coming viewWillAppear:YES];
    [going viewWillDisappear:YES];
    [UIView beginAnimations:@"View Flip" context:viewArray]; {
     [UIView setAnimationDuration:1.0];
     [UIView setAnimationDelegate:self];
     [UIView setAnimationDidStopSelector:@selector(animationDidEnd:finished:context:)];
     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

     //  coming.view.alpha = 1.0;  //uncomment these lines if we want fading of views
     //  going.view.alpha = 0.0;

     [UIView setAnimationTransition:transition forView:self.view cache:YES];
     [self.view addSubview: coming.view];
    }
    [UIView commitAnimations];

}

- (void) animationDidEnd:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
    NSArray *viewArray = context;
    [((UIViewController *)[viewArray objectAtIndex:1]).view removeFromSuperview];
    [[viewArray objectAtIndex:1] viewDidDisappear:YES];
    [[viewArray objectAtIndex:0] viewDidAppear:YES];
    [[[viewArray objectAtIndex:0] view] setUserInteractionEnabled: YES];
    [viewArray release];
}
mahboudz
I have it flipping now except for when I come back to the parent view. I'm doing this from the flip view [self.view removeFromSuperview]. Whereas you are doing this [self.view addSubview: coming.view]. My code is causing it to not animate upon returning to the parent.
4thSpace
I also can't use the animationDidEnd: code since that causes my flipped view to disappear.
4thSpace
If you called BeginAnimation and not animationDidEnd, then the calls after beginAnimation are queued up and haven't happened yet. Not a good state to leave things.When flipping a view, one view is added, the other is removed. If you don't remove it, then it stays behind your view, and you will have problems flipping back to it (at least with the above code). Keep playing with these routines until you learn what's going on. Once you've mastered you might find other ways to do it too.
mahboudz
Thanks. One thing I'm not doing is the container view you mentioned. I flip from the page view and then back. The page view is never removed from any view since that would also remove the spawned flip view. There are only ever two views. Could that be the main issue? I'm not sure how the container view fits in. I am calling both beginAnimations and animationDidEnd via the @selector.
4thSpace
I've added a rootViewController and have the other views launching from there. I'm back where I started. The first page works fine but there after, the flip view just flips over and displays itself again when leaving the flip view. Then it disappears and I see the rootViewController. Also, on the page1, after flipping back, the page control disappears.
4thSpace