自定义ViewController转换删除视图之间的间隙

时间:2013-08-12 14:23:47

标签: ios objective-c xcode

嗨我在两个视图控制器之间有一个自定义过渡,我想在转换时删除它们之间的黑色间隙。我该怎么办呢?谢谢!以下是当前使用CATransition和间隙图片执行转换的方法。 enter image description here

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

}

1 个答案:

答案 0 :(得分:0)

使用这种过渡,你只能做很多事情。你会注意到(如果你做得足够慢),当新视图进入时,它也会逐渐淡入,并且外向视图会逐渐淡出。您可以通过将窗口的背景颜色设置为与传入视图的背景颜色相同的颜色来摆脱黑色条,但您也会看到传出控制器的视图在外出时淡入该颜色。检查一下,看看你能不能看到它。

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

P.S。您应该摆脱分配init 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];
    }];
}