Frage

I platziert habe den folgenden Code in meinem Programm

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

Alles funktioniert gut, aber es gibt keine Animation, wenn ich das Projekt in den Simulator zu bauen.

Wo und wie nenne ich diese Animation? sobald ich das bekommen, dann kann ich es mit dem App Store einreichen!

War es hilfreich?

Lösung

Haben Sie Ansichten in Ihrer App oder einfach nur ein Fenster? Ich frage mich nur, wenn Sie die Animation unter alles andere sind hinzufügen. In den meisten meine Anwendungen und viele Proben von Apple gibt es ein zugrunde liegendes Hauptfenster und alle Ansichten sind oben auf, dass unter Verwendung von Viewcontrollers oder anderen Controllern aufaddiert.

Außerdem haben Sie darüber nachgedacht, die viel einfache Beginanimation mit ... commitAnimation?

Wenn Sie nur versuchen, sind die Zugabe einer Ansicht und Löschung eines andere zu animieren, sehen, meinen Code, dies zu tun mit 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];
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top