繁体   English   中英

从右向左推动时发生CATransition黑色问题

[英]CATransition black color issue when push right to left

可能是这种类型的问题发生在很多开发者身上,我也试图在Google上找到但是没有运气来解决我的问题。

在我的应用程序rootViewController动态设置窗口,我的意思是用户可以在运行时应用程序更改根视图。 首先,我从UIWindow删除当前的rootViewController ,然后在UIWindow上设置具有特定动画的新的rootViewController 这个动画由CATransition完成,带有transition.type = kCATransitionPush;
我的应用程序工作得非常好,除了新的rootViewController动画。 如上所述,我说我使用了kCATransitionPushCATransition

编辑:以下是我的代码:

-(void) changeRootViewController
{
    for(UIView *subViews in self.window.rootViewController.view.subviews)
        [subViews removeFromSuperview];
    [self.window.rootViewController.view removeFromSuperview];
    self.window.rootViewController.view = nil;
    [self.window.rootViewController removeFromParentViewController];

    MainRootViewController *mainRootVC = [[MainRootViewController alloc] init];

    CATransition *animation = [CATransition animation];
    [animation setDuration:0.4];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromRight];
    animation.fillMode = kCAFillModeForwards;
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
    self.window.rootViewController = mainRootVC;
    [[self.window layer] addAnimation:animation forKey:nil];
}

我还尝试设置UIWindow.背景的clearColorwhiteColor UIWindow. 但不行。

我的问题是:当动画是进程(从右到左)时,我会变黑。 所以任何人都可以帮我隐藏这个黑影子? 请给你金色的建议。

谢谢。

在委托中添加(didFinishLaunchingWithOptions方法)这两行:

self.window.backgroundColor = [UIColor whiteColor];
self.window.tintColor = [UIColor whiteColor];

我有同样的要求,我有3个全屏大小的图像在闪屏,应该从右向左滑动。 但使用CATransition并不能解决问题。 所以我使用了scrollview和分页。 在scrollview中添加了3个图像,然后开始动画。

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    size = [UIScreen mainScreen].bounds.size;

    imageArray = [[NSMutableArray alloc] init];
    [imageArray addObject:[UIImage imageNamed:@"splashScreen1.png"]];
    [imageArray addObject:[UIImage imageNamed:@"splashScreen2.png"]];
    [imageArray addObject:[UIImage imageNamed:@"splashScreen3.png"]];

    self.splashScrollView.frame = CGRectMake(0,0,size.width,size.height);
    self.splashScrollView.contentSize = CGSizeMake(size.width * imageArray.count, size.height);
    self.splashScrollView.pagingEnabled = YES;

    CGFloat xPos = 0.0;

    for (UIImage *image in imageArray) {
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.frame = CGRectMake(xPos, 0.0, size.width, size.height);
        [self.splashScrollView addSubview:imageView];
        xPos += size.width;
    }

    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(startAnimation) userInfo:nil repeats:NO];

}

这个(startAnimation)方法滚动scrollView到图像的宽度,在第一个图像动画完成后,我已经开始滚动到scrollview宽度边缘的第二个图像动画。

-(void) startAnimation{

    [UIView animateWithDuration:2.0
                     animations:^{

                         self.splashScrollView.contentOffset = CGPointMake(size.width, 0.0);

                     } completion:^(BOOL finished) {

                         [UIView animateWithDuration:2.0
                                          animations:^{

                                              self.splashScrollView.contentOffset = CGPointMake((self.splashScrollView.contentSize.width - CGRectGetWidth(self.splashScrollView.frame)), 0.0);


                                          } completion:^(BOOL finished) {

                                              //At animation end go to login

                                          }];


                     }];

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM