在立方体动画中切换两个视图控制器的视图

7
下面的代码实现了在一个立方体动画中两个视图之间的切换。
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];

但是,如果视图不属于self.navigationController,如何在两个视图控制器之间使用立方体动画进行切换,然后同时缩放当前视图控制器的视图?非常感谢。

1个回答

8
这对我有效:
-(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
请注意,上述所有“类型”都没有文档记录。如果你被发现使用它们,你的应用可能会被下架。此外,在任何版本更新中,这些类型可能会消失(或更名)。 - David H

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接