iphone - 用于 segue 动画的 CATransition(iOS 7 之前的样式)

标签 iphone ios cocoa-touch segue

我有一个自定义转场,试图复制 iOS 7 之前样式的推送/弹出转场:

viewControllers 并排动画,没有变暗。(真的有那么难吗!)

下面的代码有效,除了:

  • 退出页面在退出时变暗
  • 进入页面在进入时是黑色的(随着移动到位逐渐变正常)

这些图片说明了问题:

enter image description here然后... enter image description here

有没有办法阻止这种变暗的效果?如果您能提供帮助,我将不胜感激。

-(void)perform
{
    UIViewController *source = self.sourceViewController;
    UIWindow *window = source.view.window;

    CATransition *transition = [CATransition animation];
    [transition setDuration:2.0];
    [transition setDelegate:self];
    [transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
    [transition setType:@"push"];
    [transition setSubtype:kCATransitionFromRight];

    [window.layer addAnimation:transition forKey:kCATransition];
    [window setRootViewController:self.destinationViewController];
}

最佳答案

这 2 个函数对我来说工作正常,尽管代码与您的非常相似,但我希望它能有所帮助。

+(void) modalRight:(UIViewController*)vc destvc:(UIViewController*)viewCtrl{
    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromRight;
    [vc.view.window.layer addAnimation:transition forKey:nil];
    [vc presentModalViewController:viewCtrl animated:NO];
}

+(void) modalLeft:(UIViewController*)vc{
    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromLeft;
    [vc.view.window.layer addAnimation:transition forKey:nil];
    [vc dismissModalViewControllerAnimated:NO];
}

关于iphone - 用于 segue 动画的 CATransition(iOS 7 之前的样式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19093688/

相关文章:

iphone - 如何强制接收 iOS 上的反向地理编码数据的语言?

iphone - 如何实现正确的 uinavigationbar 后退按钮功能

iphone - 继承 UIImageView 的子类 - 前向声明错误

swift - 如何在我的 swift 框架中使用核心数据

iphone - 理解TTNavigator

iphone - 使用 css 多列在 UIWebView 中对 html 进行分页时出错

iphone - NSManagedObjectModel initWithContentsOfURL 返回 nil,即使 modelURL 有效

iphone - Iphone OS 3.0 上的 PJSIP 如何移植声音?

iphone - 将声音从左向右移动

iphone - iOS 将 ViewController 和 AppDelegate 设置为 CoreLocation 模型类的监听器