我已经添加了一个自定义动画过渡到视图控制器 - 显示和解散两者但它不能在iPhone 7模拟器(Xcode 8)中工作,但动画过渡在iPhone 6s和模拟器之前工作得非常好。
在iPhone 7模拟器上运行时,转换时会出现白色背景,然后显示下一个视图控制器。
不知道为什么会发生这种情况?有谁知道为什么?
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 :(得分:2)
实际上它是iPhone 7和7Plus模拟器(Xcode 8.2.1)中的一个错误,因为它在iPhone 6s和之前的模拟器以及真实设备中都能正常工作。
参考here