gpt4 book ai didi

ios - 自定义动画过渡不适用于 iPhone 7 模拟器

转载 作者:搜寻专家 更新时间:2023-10-30 20:14:08 24 4
gpt4 key购买 nike

我已将自定义动画过渡添加到 View Controller - 呈现和关闭两者,但它在 iPhone 7 模拟器 (Xcode 8) 中不起作用,但动画过渡在 iPhone 6s 和之前的模拟器中运行良好。

在 iPhone 7 模拟器上运行时,转换时出现白色背景,然后显示下一个 View Controller 。

不知道为什么会这样?有人知道为什么吗?

代码

#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;
}
}

最佳答案

实际上它是 iPhone 7 和 7Plus 模拟器 (Xcode 8.2.1) 中的一个错误,因为它在 iPhone 6s 和之前的模拟器以及真实设备中都可以正常工作。

引用here

关于ios - 自定义动画过渡不适用于 iPhone 7 模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39947877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com