Iphone 调用动画?

Iphone 调用动画?,iphone,objective-c,fade,transition,Iphone,Objective C,Fade,Transition,我已经在我的程序中放置了以下代码 CATransition *animation = [CATransition animation]; [animation setDuration:0.5]; [animation setType:kCATransitionFade]; [animation setSubtype:kCATransitionFromLeft]; [animation setTimingFunction:[CAMediaTimingFunction functio

我已经在我的程序中放置了以下代码

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"];  
一切都很好,但当我将项目构建到模拟器中时,没有动画


我在哪里以及如何称呼此动画?一旦我得到这个,然后我可以提交到应用商店

你的应用程序中有任何视图还是只有一个窗口?我只是想知道你是否在其他东西下面添加动画。在我的大多数应用程序和苹果的许多示例中,都有一个底层主窗口,所有视图都使用ViewController或其他控制器添加到主窗口之上

还有,你有没有考虑过使用更简单的beginAnimation…commitAnimation

如果您只是尝试为添加视图和删除另一个视图设置动画,请参阅我使用ViewController执行此操作的代码:

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

这是什么语言和平台的代码?不,我没有!请看一下我的完整代码。在这里我真的需要解决这个问题!非常感谢。1个主视图和SlideControl视图我将使用任何东西。让我知道!beginAnimation和commitAnimation非常容易使用。但是,这取决于您尝试设置动画的内容。现在,如果您有一个视图(位于主窗口顶部),请尝试将上面的最后一行更改为:[topView.layer addAnimation:animation forKey:@“SwitchToView1]”;我在您的源代码中看到了这一点://删除当前视图并替换为myView1[currentView removeFromSuperview];[窗口添加子视图:当前视图];我看不到您在哪里添加view1。您正在删除currentView并将其添加回。如果这具有所需的结果,即当您查看应用程序时,它看起来像您想要的,则继续并使用:[currentView.layer addAnimation:animation forKey:@“SwitchToView1]”触发您的动画;