3
私は、ビューコントロールにカスタムアニメーショントランジションを追加しました - 両方とも提示され、却下されましたが、iPhone 7 Simulator(Xcode 8)では動作しませんが、アニメーショントランジションはiPhone 6sシミュレータの前に。カスタムアニメーショントランジションがiPhone 7シミュレータで動作しない
iPhone 7 Simulatorで実行されると、移行中に白い背景が表示され、次のviewcontrollerが表示されます。
なぜそれが起こっているのか分かりませんか?なぜ誰が知っていますか?
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;
}
}
コードを表示できますか? (それがたくさんある場合は、githubにプロジェクトを投稿してください。)ありがとう。 – matt
@mattコードを記述しました –