ios动画的黑色背景



当用动画改变控制器时,我看到背景是黑色的。我试着用不同的方法来改变它,但都不起作用。该怎么办?

self.view.backgroundColor = [UIColor whiteColor];
self.view.layer.backgroundColor = [UIColor whiteColor].CGColor;
self.view.window.backgroundColor = [UIColor whiteColor];
self.view.window.layer.backgroundColor = [UIColor whiteColor].CGColor;
UIApplication.sharedApplication.windows.firstObject.backgroundColor = [UIColor whiteColor];
[UIApplication sharedApplication].windows.lastObject.rootViewController.view.backgroundColor = [UIColor whiteColor];
[UIApplication sharedApplication].windows.lastObject.rootViewController.view.layer.backgroundColor = [UIColor whiteColor].CGColor;
[UIApplication sharedApplication].windows.firstObject.rootViewController.view.backgroundColor = [UIColor whiteColor];
[UIApplication sharedApplication].windows.firstObject.rootViewController.view.layer.backgroundColor = [UIColor whiteColor].CGColor;
[UIApplication sharedApplication].windows.firstObject.screen.focusedView.backgroundColor = [UIColor whiteColor];
UIScene *scene = [[[[UIApplication sharedApplication] connectedScenes] allObjects] firstObject];
if([scene.delegate conformsToProtocol:@protocol(UIWindowSceneDelegate)]){
UIWindow *window = [(id <UIWindowSceneDelegate>)scene.delegate window];
window.backgroundColor = [UIColor whiteColor];
}
ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController2"];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromLeft;
[self.view.window.layer addAnimation:transition forKey:kCATransition];
[self presentViewController:vc animated:NO completion:nil];

我建议你重构你的代码使用UIViewControllerTransitioningDelegate和UIViewControllerAnimatedTransitioning。

你也可以用CGAffineTransform创建一个UIView动画来变换视图,如下所示:

ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController2"];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self.view.superview addSubview:vc.view];
CGAffineTransform firstTransform = CGAffineTransformMakeTranslation(-1 * self.view.frame.size.width, 0);
vc.view.transform = firstTransform;
[UIView animateWithDuration:0.50 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
vc.view.transform =  CGAffineTransformTranslate(firstTransform, self.view.frame.size.width, 0);
} completion:^(BOOL finished) {
[self presentViewController:vc animated:NO completion:nil];
}];

相关内容

  • 没有找到相关文章

最新更新