1

我正在使用以下代码在带有 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];

它的功能主要是我想要的。它应该从顶部推动,但是由于某种原因它的行为很奇怪。首先,我要切换到的视图应该从底部进入,但由于某种原因,我要切换到的视图以低不透明度出现在它的顶部,所以你可以看到它们。但是,您还会看到进来的视图,在其自身和另一个视图之上,向上移动了 100 像素,再次具有低不透明度。就在过渡的中点之前,一切正常,你只看到进来的视图和出去的视图,做他们应该做的事情。但是在中途点之后,我正在切换到的视图出现在其最终目的地,在我正在切换的视图下,并且我正在切换的视图的不透明度降低了。

这里发生了什么?

4

2 回答 2

0

你也可以使用这种方式

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];

如果使用它,将没有背景视图,您将看到当前视图的白屏。但是如果添加子视图,则需要手动删除子视图。

于 2010-12-24T07:20:55.763 回答
0

我真的不明白你想要什么,但希望这段代码有助于实现,如果不是,那么告诉你更多关于你 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];
    }
}
于 2010-12-24T07:07:44.680 回答