views:

195

answers:

1

I have placed the following code in my program

CATransition *animation = [CATransition animation];  
[animation setDuration:0.5];  
[animation setType:kCATransitionFade];  
[animation setSubtype:kCATransitionFromLeft];  
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];  
   [[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];

Everything works great but there is no animation when I build the project into the simulator.

Where and how do I call this animation? once I get this then I can submit it to the app store!

+1  A: 

Do you have any views in your app or just a Window? I'm just wondering if you're adding the animation beneath everything else. In most of my apps and many of Apple's samples, there is an underlying MainWindow and all views are added up on top of that using ViewControllers or other controllers.

Also, have you thought about using the much simpler beginAnimation...commitAnimation?

If you're merely trying to animate the addition of a view and deletion of another, see my code for doing this with viewControllers:

- (void)switchTwoViews:(UIViewController *)view1 otherView:(UIViewController *)view2 cacheTheView:(BOOL) cache;
{
    /*
     This method is called when the info or Done button is pressed.
     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;
    }
    // [coming.view setFrame:CGRectMake(0, 0, 480, 320)];


    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];

     [UIView setAnimationTransition:transition forView:self.view cache:cache];
     [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
no i haven't! please take a look at my full code. here. I really need this solved! thank you!http://www.iphonedevsdk.com/forum/iphone-sdk-development/28174-transitions-fading.html#post122649
Dane
1 main view with a slidecontroller view
Dane
I will use anything. let me know!
Dane
beginAnimation and commitAnimation are pretty easy to use. However, it depends on what you are trying to animate.Now, if you have a view (sitting on top of the mainWindow), then try changing your last line above to: [topView.layer addAnimation:animation forKey:@"SwitchToView1"];
mahboudz
I saw this in your source: // remove the current view and replace with myView1 [currentView removeFromSuperview]; [theWindow addSubview:currentView];I don't see where you are adding view1. You are removing currentView and adding it right back in. If this has the desired result, i.e. when you are looking at the app it looks like what you want, then go ahead and trigger your animation with:[currentView.layer addAnimation:animation forKey:@"SwitchToView1"];
mahboudz
I hate to say it, but I feel like you've copy-pasted a lot of your code without really understanding what the code does. While it may seem to be working, I would hesitate to "submit it to the app store" without a bit more study.
mahboudz