2016-10-09 20 views
3

Ich habe eine benutzerdefinierte animierte Übergang zu einem Viewcontroller hinzugefügt - präsentiert und entlassen beide, aber es funktioniert nicht in iPhone 7 Simulator (Xcode 8), aber dass animierte Übergang funktioniert einwandfrei in iPhone 6s und vor Simulatoren.Benutzerdefinierte animierte Übergang funktioniert nicht auf dem iPhone 7 Simulator

Beim Ausführen auf dem iPhone 7 Simulator erscheint beim Übergang ein weißer Hintergrund und dann der nächste Viewcontroller.

Weiß nicht, warum es passiert? Weiß jemand warum?

CODE

#import "HEREINExpandAnimator.h" 

#define kTransitionDuration 0.65 

@interface HEREINExpandAnimator() 
{ 
    UIView *topView; 
    UIView *bottomView; 
} 

@end 
@implementation HEREINExpandAnimator 


+ (id)animator { 
    static HEREINExpandAnimator *animator = nil; 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     animator = [[self alloc] init]; 
    }); 
    return animator; 
} 

#pragma mark - UIViewControllerAnimatedTransitioning 

- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext 
{ 
    return kTransitionDuration; 
} 

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext 
{ 
    // From VC 
    UIViewController *fromController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 

    CGRect fromViewFrame = fromController.view.frame; 

    // To VC 
    UIViewController *toController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 

    // Container View 
    UIView* container = [transitionContext containerView]; 


    if (self.transitionMode == Presented) { 

     //create snapshots 
     topView = [fromController.view resizableSnapshotViewFromRect:fromViewFrame afterScreenUpdates:YES withCapInsets:UIEdgeInsetsMake(self.openingFrame.origin.y, 0, 0, 0)]; 
     topView.frame = CGRectMake(0, 0, fromViewFrame.size.width, self.openingFrame.origin.y); 

     //add our snapshots on top 
     [container addSubview:topView]; 



     bottomView = [fromController.view resizableSnapshotViewFromRect:fromViewFrame afterScreenUpdates:YES withCapInsets:UIEdgeInsetsMake(0, 0, fromViewFrame.size.height - self.openingFrame.origin.y - self.openingFrame.size.height , 0)]; 
     bottomView.frame = CGRectMake(0, self.openingFrame.origin.y + self.openingFrame.size.height, fromViewFrame.size.width, fromViewFrame.size.height - self.openingFrame.origin.y - self.openingFrame.size.height); 

     [container addSubview:bottomView]; 



     // Take snapshot of the to viewcontroller and change the height to the opening frame. 

     UIView *snapshotView = [toController.view resizableSnapshotViewFromRect:fromViewFrame afterScreenUpdates:YES withCapInsets:UIEdgeInsetsZero]; 
     snapshotView.frame = self.openingFrame; 


     [container addSubview:snapshotView]; 

     toController.view.alpha = 0.0; 
     [self changeAlphaOfView:fromController.view withAlpha:0.0]; 

     [container addSubview:toController.view]; 


     [UIView animateWithDuration:kTransitionDuration delay:0 usingSpringWithDamping:0.85 initialSpringVelocity:1.5 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
      //adjust the new frames 

      topView.frame = CGRectMake(0, -topView.frame.size.height, topView.frame.size.width, topView.frame.size.height); 
      bottomView.frame = CGRectMake(0, fromViewFrame.size.height, bottomView.frame.size.width, bottomView.frame.size.height); 

      snapshotView.frame = toController.view.frame; 

     } completion:^(BOOL finished) { 
      //don't forget to clean up 

      [UIView animateWithDuration:0.33 animations:^{ 
       [snapshotView removeFromSuperview]; 
      }]; 


      toController.view.alpha = 1.0; 
      [self changeAlphaOfView:fromController.view withAlpha:1.0]; 

      [transitionContext completeTransition:finished]; 
     }]; 
    } 
    else { 

     UIView *snapshotView = [fromController.view resizableSnapshotViewFromRect:fromController.view.bounds afterScreenUpdates:YES withCapInsets:UIEdgeInsetsZero]; 
     [container addSubview:snapshotView]; 

     fromController.view.alpha = 0.0; 

     [self changeAlphaOfView:toController.view withAlpha:0.0]; 


     [UIView animateWithDuration:0.55 delay:0 usingSpringWithDamping:1 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{ 
      topView.frame = CGRectMake(0, 0, topView.frame.size.width, topView.frame.size.height); 
      bottomView.frame = CGRectMake(0, fromController.view.frame.size.height - bottomView.frame.size.height, bottomView.frame.size.width, bottomView.frame.size.height); 

      snapshotView.frame = self.openingFrame; 

     } completion:^(BOOL finished) { 
      [snapshotView removeFromSuperview]; 

      fromController.view.alpha = 1.0; 
      [self changeAlphaOfView:toController.view withAlpha:1.0]; 

      [transitionContext completeTransition:finished]; 
     }]; 


    } 


} 




-(void)changeAlphaOfView:(UIView *)contentView withAlpha:(CGFloat)alpha { 
    contentView.backgroundColor = [UIColor whiteColor]; 
    for (UIView *view in contentView.subviews) { 
     view.alpha = alpha; 
    } 
} 
+0

Können Sie Ihren Code zeigen? (Wenn es viel davon gibt, posten Sie ein Projekt auf GitHub.) Danke. – matt

+0

@matt Ich habe den Code erwähnt –

Antwort

2

Eigentlich ist es ein Fehler in iPhone 7 und 7Plus Simulator (Xcode 8.2.1), als seine adaequat in iPhone 6s und früheren Simulatoren und auch zu in realen Geräten.

Siehe here

Verwandte Themen