Pergunta

Eu coloquei o seguinte código no meu programa

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

Tudo funciona muito bem, mas não há nenhuma animação quando eu construir o projeto no simulador.

Onde e como eu chamo essa animação? uma vez que recebo isso, então eu posso enviá-lo para a loja app!

Foi útil?

Solução

Você tem vistas em seu aplicativo ou apenas uma janela? Eu só estou querendo saber se você está adicionando a animação abaixo tudo o resto. Na maioria dos meus aplicativos e muitas das amostras da Apple, há uma MainWindow subjacente e todas as vistas são adicionados em cima de que o uso de ViewControllers ou outros controladores.

Além disso, você já pensou em usar o muito mais simples BeginAnimation ... commitAnimation?

Se você está apenas tentando animar a adição de uma vista e eliminação de outro, ver o meu código para fazer isso com 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];
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top