我可以为CATransition设置最大alpha吗? [英] Can I set maximum alpha for CATransition?

查看:85
本文介绍了我可以为CATransition设置最大alpha吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 CATransition 中调整视图淡入和淡出的最大alpha(不透明度)?

Is it possible to adjust the maximum alpha (opacity) in a CATransition for when the views fade in and out?

我想要的是看起来像模态的东西。与默认模态序列相比, CATransition 给出的过渡非常戏剧性。

What I want is something that looks like a modal segue. Compared to a default modal segue, the transition given by CATransition is very «dramatic».

说我有两个观点。
答:我要从中转换的视图。
B:我想过渡到的视图。

Say I have two views. A: the view I want to transition from. B: the view I want to transition to.

我希望B从底部移到A上方。为此,我使用 kCATransitionMoveIn 类型,其子类型为 kCATransitionFromTop (这很奇怪,因为B从底部而不是顶部向上移动)。

I want B to come moving in from the bottom over A. For this I use the kCATransitionMoveIn type, with subtype kCATransitionFromTop (which is weird because B is moving up from bottom, not top).

在默认的模态segue中,这很好用,并且A只是变灰了一点。使用 CATransition ,当B移至A上方约70%时,A在过渡结束时全黑。

In the default modal segue, this works fine, and A is only greyed out a little. With CATransition, A is totally black at towards the end of the transition when B has moved about 70% over 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;

问题源于

The problem originates from here.

推荐答案

经过一些挖掘另外,我认为您根本无法为开箱即用的CATransition设置最大不透明度/ alpha。

After digging around some more I figured that you simply can't set a maximum opacity / alpha for the CATransition that you get out of the box.

所以我这样解决了: p>

So I solved it like this:

//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..");
     }];

这篇关于我可以为CATransition设置最大alpha吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆