为什么我的CATransitions会起作用?

我使用以下代码在CATransition之间切换视图。
CATransition *applicationLoadViewIn = [CATransition animation];

    [applicationLoadViewIn setDuration:20];

    [applicationLoadViewIn setType:kCATransitionPush];

    [applicationLoadViewIn setSubtype:kCATransitionFromTop];

    [applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];

    ViewToSwitchTo *myviewcontroller = [[ViewToSwitchTo alloc] init];

    [self.view.layer addAnimation:applicationLoadViewIn forKey:kCATransitionPush];

    [self.view addSubview:myviewcontroller.view];
它的功能主要是我想要的。它应该从顶部推出,但它出于某种原因行为奇怪。首先,我切换到的视图开始从底部开始,但由于某种原因,我正在切换FROM的视图出现在它的顶部,具有低不透明度,因此您可以看到它们。但是,您还会看到正在进入的视图,可能会向上移动100个像素,在其自身和另一个视图上移动,再次使用低不透明度。就在转换的中间点之前,一切正常,你只能看到正在进入的视图,视图就会消失,做他们应该做的事情。但是在中途点之后,我切换到的视图出现在其最终目的地,在我正在切换的视图下,并且我正在切换的视图的不透明度已降低。 这里发生了什么?     
已邀请:
我真的不明白你想要什么,但希望这段代码有助于实现,如果没有,那么告诉你更多关于你的CATransition
-(void) startAnimation {
    fullImageView.alpha = 0.50;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationRepeatCount:1];
    [UIView setAnimationRepeatAutoreverses:NO];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(pulseAnimationDidStop:finished:context:)];
    fullImageView.alpha = 1.0;
    [UIView commitAnimations];
}

- (void)pulseAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    if(hasFocus) {
        [self startAnimation];
    } else {
        fullImageView.alpha = 1.0;
    }
}

-(void) setHasFocus:(BOOL)_hasFocus {
    hasFocus = _hasFocus;
    if(hasFocus) {
        [self startAnimation];
    }
}
    
你也可以用这种方式
CATransition *applicationLoadViewIn = [CATransition animation];
    [applicationLoadViewIn setDuration:1.5];
    [applicationLoadViewIn setType:kCATransitionPush];
    [applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
    //[applicationLoadViewIn setRepeatCount:114];

    productVC=[[PoductViewController alloc]initWithNibName:@"PoductViewController" bundle:[NSBundle mainBundle]];

    [[productVC.view layer] addAnimation:applicationLoadViewIn forKey:kCATransitionPush];
    [self.view addSubview:productVC.view];
但我建议您使用导航控制器代替
[self.view addSubview:productVC.view];
只是用
[self.navigationController pushViewController:productVC animated:YES];
如果你使用它,将没有背景视图,你会看到当前视图的白色屏幕。但是如果添加子视图,则需要手动删除子视图。     

要回复问题请先登录注册