代码之家  ›  专栏  ›  技术社区  ›  Sumit Kumar Saha

UIAnimation后UI屏幕变黑

  •  0
  • Sumit Kumar Saha  · 技术社区  · 8 年前

    我的问题是。。。 我有父视图控制器的对象,我想在上面设置第二个视图控制器的动画。 所以我在parentvc的视图上添加了一个子视图backgroundview。视图,然后是需要在背景视图上绘制的视图。 但在动画完成一秒钟后,我可以看到我想要的视图,但随后它被一个完整的黑屏所取代。

    我认为我的最高观点已经被重新画出来了,所以我该如何纠正这个问题。

    代码:-

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        //_colorCaptureOptions = [NSArray arrayWithObjects: @"Camera", @"Color Slider / Color Wheel", nil];
    
        mExtractionQueue = [[NSOperationQueue alloc] init];
        [mExtractionQueue setMaxConcurrentOperationCount:1];
    
    
        CGRect screenRect = [[UIScreen mainScreen] bounds];
    
        //CGRect screenRect = self.view.frame;
    
        self.backgroundView = [[UIView alloc] initWithFrame:screenRect];
        self.backgroundView.backgroundColor = [UIColor clearColor];
    
        [self.parentVC addChildViewController:self];
        [self.parentVC.view addSubview:self.backgroundView];
        //[self didMoveToParentViewController:self.parentVC];
    
        UITapGestureRecognizer *guideTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleScrimSelected)];
    
        [self.backgroundView addGestureRecognizer:guideTap];
        [self.backgroundView addSubview:self.view];
    }
    
    -(void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
    
        if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
            CGRect screenRect = [[UIScreen mainScreen] bounds];
    
            CGFloat viewHeight = 150;
    
            self.backgroundView.alpha = 0.0;
            self.view.alpha = 1;
            self.view.frame = CGRectMake(0, screenRect.size.height, screenRect.size.width, viewHeight);
    
    
            [UIView animateWithDuration:0.2
                                  delay:0
                                options: UIViewAnimationOptionCurveEaseInOut
                             animations:^{
                                 self.backgroundView.alpha = 1.0;
    
                                 self.view.frame = CGRectMake(0, screenRect.size.height - viewHeight, screenRect.size.width, viewHeight);
                             }
                             completion:^(BOOL _finished) {
            }];
        }
    }
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Igor Kislyuk    8 年前

    好吧,为了清晰起见,你最好提供一些截图。
    对于其他所有人:

    1. 可能,您的背景视图只是黑色的,这会导致黑屏。甚至是这样 [UIColor clearColor]

    2. childViewController,它会破坏MVC

    3. 最好不要改变框架

    4. 如果要用动画演示另一个控制器,请使用以下命令 UIViewControllerTransitioningDelegate 还有这个 UIViewControllerAnimatedTransitioning 在对象中,所以 不要重塑过渡 custom controller transition tutorial

    希望这能帮助你

    编辑: [UIColor clearColor] 完全删除颜色,这意味着您将没有任何颜色。

    现在对你来说最好的解决方案是重写这些控制器,将它们分开,去掉viewControllers的容器,将动画更改为自定义,然后问题就会神奇地消失。如果您解决了问题,请不要忘记将问题标记为已解决