0

嗨,我有两个视图控制器之间的自定义转换,我想在转换时消除它们之间的黑色间隙。我能做些什么来做到这一点?谢谢!这是当前使用 CATransition 和间隙图片执行转换的方式。在此处输入图像描述

- (void)bottomButtonScreen4:(UIGestureRecognizer *)gestureRecognizer {
    NSLog(@"Swipe Up Worked");

    settingsViewController = [[SettingsViewController alloc] init];

    CATransition* transition = [CATransition animation];
    transition.duration = 0.5;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromTop;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];

    settingsViewController = [self.storyboard instantiateViewControllerWithIdentifier: @"settingView"];

    [self.navigationController pushViewController:settingsViewController animated:NO];

}
4

1 回答 1

0

使用这个过渡,你能做的只有这么多。你会注意到(如果你让它足够慢的话)随着新视图的移动,它也在淡入,而传出的视图也在淡出。您可以通过将窗口的背景颜色设置为与传入视图的背景颜色相同的颜色来消除黑条,但您还会看到传出控制器的视图在消失时淡出该颜色。检查一下,看看这是否是您可以忍受的外观。

self.view.window.backgroundColor = settingsViewController.view.backgroundColor;

PS 你应该去掉你分配初始化 settingsViewController 的那一行。它现在没有做任何事情,无论如何它是获取该实例的错误方法。

编辑后:

另一种摆脱黑条问题的方法是像这样使用 animateWithDuration :

-(IBAction) pushViewControllerFromTop {
    CGFloat height = self.view.bounds.size.height;
    UIViewController *settingsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Blue"];
    settingsViewController.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y - height, self.view.frame.size.width, self.view.frame.size.height);
    [self.view.superview addSubview:settingsViewController.view];
    [UIView animateWithDuration:.5 animations:^{
        self.view.center = CGPointMake(self.view.center.x, self.view.center.y + height);
        settingsViewController.view.center = CGPointMake(settingsViewController.view.center.x, settingsViewController.view.center.y + height);

    } completion:^(BOOL finished) {
        [self.navigationController pushViewController:settingsViewController animated:NO];
    }];
}
于 2013-08-12T15:28:00.420 回答