2010-12-30 13 views
7

den folgenden Code implementieren Sie den Schalter zwischen zwei Ansicht in einer Cube-Animation.wechseln Sie zwei View-Controller-Ansicht in einer Cube-Animation

UIViewController* viewCtrl = [[UIViewController alloc] init:book]; 

CATransition *transition = [CATransition animation]; 
transition.duration = 1; 
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
transition.type = @"cube"; 
transition.subtype = kCATransitionFromLeft; 
transition.delegate = self; 
[self.navigationController.view.layer addAnimation:transition forKey:nil]; 
self.navigationController.navigationBarHidden = NO; 
[self.navigationController pushViewController:viewCtrl animated:YES];  

[viewCtrl release]; 

aber, wenn der Blick auf self.navigationController gehört nicht, wie Schalter in Würfeln Animation zwischen zwei View-Controller zu tun, und dann, wie die aktuellen View-Controller-Ansicht in der gleichen Zeit zu skalieren? sehr vielen Dank

Antwort

8

Dieser arbeitet für mich:

-(IBAction)animate:(id)sender { 
    NSLog(@"animate"); 

    CATransition *transition = [CATransition animation]; 
    transition.delegate = self; 
    transition.duration = 0.8; 
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    NSString *types[4] = {@"cube", @"rippleEffect", @"cube", @"alignedCube"}; 
    NSString *subtypes[4] = {kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromRight}; 

    transition.type = types[0]; 
    transition.subtype = subtypes[1]; 

    [self.view.layer addAnimation:transition forKey:nil]; 

    SecondView *_secondViewController = [[SecondView alloc]initWithNibName:@"secondView" bundle:nil]; 
    self.secondViewController = _secondViewController; 
    _secondViewController = nil; 

    [[[self view] layer] addAnimation: transition forKey: nil]; 
    [[self view] addSubview: [self.secondViewController view]]; 
} 

-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag{ 
    [self.view release]; 
} 
+5

Beachten Sie, dass alle von dem ‚Typ‘ oben ohne Papiere und wenn Sie sie Ihre App gezogen bekommen entdeckt verwenden könnte. Außerdem könnten sie in jeder Punktfreigabe weggehen (oder umbenannt werden). –

Verwandte Themen