当视图淡入和淡出时,是否可以调整CATransition
中的最大alpha(不透明度)?
我想要的是看起来像模态的东西。与默认模态segue相比,CATransition
给出的转换非常“戏剧性”。
说我有两个观点。 答:我想要转换的视图。 B:我要转换到的视图。
我希望B从A的底部进入。为此,我使用kCATransitionMoveIn
类型,子类型kCATransitionFromTop
(这很奇怪,因为B从底部向上移动,而不是顶部)
在默认模态segue中,这样可以正常工作,而A只是灰显了一点。使用CATransition
时,当A比A移动约70%时,A在转换结束时完全是黑色。
代码:
UIStoryboard *loginBoard = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
UIViewController *vc = [loginBoard instantiateInitialViewController];
UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
[keyWindow insertSubview:vc.view belowSubview:keyWindow.rootViewController.view];
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromTop;
[keyWindow.layer addAnimation:transition forKey:kCATransition];
[keyWindow.rootViewController.view removeFromSuperview];
keyWindow.rootViewController = vc;
问题源于here。
答案 0 :(得分:0)
在挖掘了一些之后我发现你根本无法为开箱即用的CATransition设置最大不透明度/ alpha值。
所以我这样解决了:
//offset the frame
vc.view.frame = CGRectMake(0, CGRectGetHeight(self.view.bounds), CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
[UIView animateWithDuration:5
animations:^{
//insert over/before root view instead of after
[keyWindow insertSubview:vc.view aboveSubview:keyWindow.rootViewController.view];
vc.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
keyWindow.rootViewController.view.alpha = 0.8;
}
completion:^(BOOL finished) {
NSLog(@"completed! now you can change the rootviewcontroller etc..");
}];