查看过渡动画

Jac*_*ins 4 animation views objective-c ios

我有这个代码:

- (void) displayView:(int)intNewView{

NSLog(@"%i", intNewView);
[currentView.view removeFromSuperview];
[currentView release];

switch (intNewView) {
    case 1:
        currentView = [[EnterView alloc] init];
        break;
    case 2:
        currentView = [[MainMenuView alloc] init];
        break;
    case 3:
        currentView = [[DetailsView alloc] init];
        break;
    case 4:
        currentView = [[PhotosView alloc] init];
        break;
    case 5:
        currentView = [[CustomUITableViewViewController alloc] init];
        break;
}

[self.view addSubview:currentView.view]; 
Run Code Online (Sandbox Code Playgroud)

}

这段代码成功地转换了视图,但是它并不像你想象的那样非常壮观(视图只是在没有动画的情况下切换).我想知道是否有一种简单的方法可以在这里添加任何类型的简单视图过渡动画?我无法弄清楚如何实现我在网上找到的任何一个例子.任何动画都足够了,只是为了调整一些东西:)

谢谢,

插口

Jul*_*per 7

您可以简单地使用基本核心动画:

像这样:

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:2];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft  forView:self.view cache:YES];


[self.view addSubview:currentView.view];

[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)

您可以尝试不同的UIViewAnimationTransitions,对于"forView",您可以进入当前在屏幕上的视图.希望有所帮助.