switch two view controller's view in a cube animation

后端 未结 1 1643
余生分开走
余生分开走 2021-02-06 09:39

the code below implement the switch between two view in a cube animation .

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

CATransition *tran         


        
相关标签:
1条回答
  • 2021-02-06 10:02

    This worked for me:

    -(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];
    }
    
    0 讨论(0)
提交回复
热议问题