【问题标题】:CATransition black color issue when push right to left从右向左推时 CATransition 黑色问题
【发布时间】:2014-09-23 00:34:14
【问题描述】:

可能很多开发者都出现过这类问题,我也尝试在谷歌上找到,但没有解决我的问题。

在我的应用程序rootViewController 中动态设置窗口,我的意思是用户可以在运行时应用程序更改根视图。所以首先我从UIWindow 中删除当前的rootViewController,然后在UIWindow 上设置新的rootViewController 并使用特定的动画。 此动画由CATransitiontransition.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,但不起作用。

我的问题是:虽然动画正在处理(从右到左),但我得到了黑色阴影。所以有人可以帮我隐藏这个黑影吗?请给你黄金建议。

谢谢。

【问题讨论】:

  • 请出示您用来制作动画的代码。
  • 将动画持续时间设置为 0。[animation setDuration:0.0]; 我知道这不是更好的方法,但我们无法移除那个黑色阴影。
  • 其他关于根视图控制器动画的问题/答案似乎使用了不同的方法。你试过那些吗? stackoverflow.com/questions/8053832/…
  • @YogeshSuthar - 那我该如何展示我的动画??
  • @Droppy - 我检查了它,但没有像从右向左推这样的动画。都是关于翻转或淡入淡出:(

标签: ios objective-c cocoa-touch catransition


【解决方案1】:

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

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

【讨论】:

  • 我发现设置 tintColor 是不必要的,并且也会产生改变我的标签视图控制器色调的不良副作用。
【解决方案2】:

我有同样的要求,我在初始屏幕上有 3 个全屏尺寸的图像,应该从右向左滑动。但是使用 CATransition 并不能解决问题。所以我使用了滚动视图和分页。在滚动视图中添加 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];

}

This(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

                                          }];


                     }];

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多