2015-03-02 6 views
0

Между моими переменами сцены на короткое время появляется уродливый черный фон. Мне сказали, что удаление анимации и задержки предотвратит это, но это не сработало.черный переход в анимации ios app

Это влияет только на переходы между вопросами викторины - другие страницы в приложении прекрасны. Файлы json для этих вопросов являются бэкэнд.

Вот код анимации для отображения вопрос engine.m

-(void)attachDelegate:(id<QuestionViewControllerDelegate>)delegate{ 
self.questionController1.delegate = delegate; 
self.questionController2.delegate = delegate; 
} 

-(BOOL)showNextQuestion:(NSArray*)questions inMainView:(UIView*)mainView{ 

if(self.nextIndex < questions.count){ 

    QuestionViewController* controller = self.nextIndex % 2 == 0 ? 

self.questionController1 : self.questionController2; 
    QuestionViewController* currentController = self.nextIndex % 2 == 1 ? 
    self.questionController1 : self.questionController2; 

    controller.question = questions[self.nextIndex]; 

    if(self.nextIndex == 0){ 

     [controller.view setTranslatesAutoresizingMaskIntoConstraints:NO]; 
     [mainView addSubview:controller.view]; 
     ConstraintsPackage* controllerPackage = [self 
addConstraintsToSuperview:mainView subview:controller.view]; 
     controller.view.tag = 0; 


     [currentController.view 
setTranslatesAutoresizingMaskIntoConstraints:NO]; 
     [mainView addSubview:currentController.view]; 
     ConstraintsPackage* currentControllerPackage = [self 
    addConstraintsToSuperview:mainView 

subview:currentController.view];   
currentController.view.tag = 1; 

     self.constraintPackages = @[controllerPackage, 
currentControllerPackage]; 
    } 

    [controller loadData]; 
    [self removeController:currentController andShowController:controller 
inMainView:mainView]; 


    self.nextIndex++; 
    return YES; 
}else{ 

    [self.questionController1.view removeFromSuperview]; 
    [self.questionController2.view removeFromSuperview]; 
    return NO; 
} 


} 

-(void)removeController:(UIViewController*)fromViewController 
andShowController:(UIViewController*)toViewController inMainView: 
(UIView*)mainView{ 

NSTimeInterval duration = 0.3; 

ConstraintsPackage* fromPackage = (ConstraintsPackage*)self.constraintPackages[fromViewController.view.tag]; 

ConstraintsPackage* toPackage = (ConstraintsPackage*)self.constraintPackages[toViewController.view.tag]; 

CGFloat toValue = 0; 
CGFloat fromValue = mainView.frame.size.width; 
[mainView layoutIfNeeded]; 

[UIView animateWithDuration:duration animations:^{ 

    fromPackage.centerXConstraint.constant = -fromValue; 
    toPackage.centerXConstraint.constant = toValue; 
    [mainView layoutIfNeeded]; 

} completion:^(BOOL finished) { 

    fromPackage.centerXConstraint.constant = 2*mainView.frame.size.width; 
}]; 

if (SYSTEM_VERSION_LESS_THAN(@"8.0")) { 
    [fromViewController viewDidAppear:YES]; 
    [toViewController viewDidAppear:YES]; 
} 

}

А вот код из dropanimationcontroller.m

@implementation DropAnimationController 

-(id)init{ 
self = [super init]; 

if(self){ 

    self.presentationDuration = 0.6; 
    self.dismissalDuration = 0.6; 
} 

return self; 
} 

-(NSTimeInterval)transitionDuration:   
    (id<UIViewControllerContextTransitioning>)transitionContext{ 

return self.isPresenting ? self.presentationDuration : 
    self.dismissalDuration; 

} 

-(void)animateTransition: 
    (id<UIViewControllerContextTransitioning>)transitionContext{ 

if(self.isPresenting){ 
    [self executePresentationAnimation:transitionContext]; 
} 
else{ 
    [self executeDismissalAnimation:transitionContext]; 
} 

} 

-(void)executePresentationAnimation:  
(id<UIViewControllerContextTransitioning>)transitionContext{ 

UIView* inView = [transitionContext containerView]; 

UIViewController* toViewController = [transitionContext 
viewControllerForKey:UITransitionContextToViewControllerKey]; 

UIViewController* fromViewController = [transitionContext 
viewControllerForKey:UITransitionContextFromViewControllerKey]; 

UIView* blurredView = [self getBlurredImage:fromViewController.view]; 
blurredView.alpha = 0.0; 
[inView addSubview:blurredView]; 

[inView addSubview:toViewController.view]; 

CGPoint centerOffScreen = inView.center; 

centerOffScreen.y = (-1)*inView.frame.size.height; 
toViewController.view.center = centerOffScreen; 

[UIView animateWithDuration:self.presentationDuration delay:0.0f 
usingSpringWithDamping:0.4f initialSpringVelocity:6.0f 
options:UIViewAnimationOptionCurveEaseIn animations:^{ 

    toViewController.view.center = inView.center; 
    fromViewController.view.alpha = 0.6; 
    blurredView.alpha = 1.0; 

} completion:^(BOOL finished) { 

    [transitionContext completeTransition:YES]; 
}]; 
} 

-(void)executeDismissalAnimation: 
(id<UIViewControllerContextTransitioning>)transitionContext{ 

UIView* inView = [transitionContext containerView]; 

UIViewController* toViewController = [transitionContext 
viewControllerForKey:UITransitionContextToViewControllerKey]; 

UIViewController* fromViewController = [transitionContext 
viewControllerForKey:UITransitionContextFromViewControllerKey]; 

UIView* blurredView = [self getBlurredImage:toViewController.view]; 
blurredView.alpha = 1.0; 
[inView addSubview:blurredView]; 

[inView insertSubview:toViewController.view 
belowSubview:fromViewController.view]; 

CGPoint centerOffScreen = inView.center; 
centerOffScreen.y = (-1)*inView.frame.size.height; 

[UIView animateKeyframesWithDuration:self.dismissalDuration delay:0.0f 
options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{ 

    [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.5 
animations:^{ 

     CGPoint center = fromViewController.view.center; 
     center.y += 50; 
     fromViewController.view.center = center; 
     blurredView.alpha = 0.0; 
    }]; 

    [UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.5 
animations:^{ 

     fromViewController.view.center = centerOffScreen; 
     toViewController.view.alpha = 1.0; 

    }]; 


} completion:^(BOOL finished) { 
    [transitionContext completeTransition:YES]; 
}]; 
} 


-(UIView*)getBlurredImage:(UIView*)view{ 
UIGraphicsBeginImageContext(view.frame.size); 
[view drawViewHierarchyInRect:view.frame afterScreenUpdates:YES]; 
UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

UIImage* blurredImage = [image applyBlurWithRadius:2.0 tintColor:[UIColor 
colorWithWhite:0.0 alpha:0.4f] saturationDeltaFactor:1 maskImage:nil]; 

UIImageView* imageView = [[UIImageView alloc] initWithFrame:view.frame]; 
imageView.image = blurredImage; 

return imageView; 

} 


@end 
+0

Можете ли вы показать код для вашей анимации? – AdamPro13

ответ

2

я думаю, что принимая фон цвет окна. Пожалуйста, попробуйте это, это может помочь u.

self.window.backgroundColor = [UIColor whiteColor];

Смежные вопросы