当执行转换时,sourceVIEwController将变为黑色,然后进行缩放.
尝试将pushVIEwController设置为完成块,但转换不会完全执行.
- (voID)perform { UIVIEwController *sourceVIEwController = (UIVIEwController *) self.sourceVIEwController; UIVIEwController *destinationVIEwController = (UIVIEwController *) self.destinationVIEwController; [destinationVIEwController.vIEw settransform:CGAffinetransformMakeScale(0.5,0.5)]; [destinationVIEwController.vIEw setAlpha:0.0]; [UIVIEw animateWithDuration:0.5 delay:0.0 options:UIVIEwAnimationCurveEaSEOut animations:^{ [destinationVIEwController.vIEw settransform:CGAffinetransformMakeScale(1.0,1.0)]; [destinationVIEwController.vIEw setAlpha:1.0]; [sourceVIEwController.navigationController pushVIEwController:destinationVIEwController animated:NO]; } completion:^(BOol finished){ }];}
我做错了什么?
解决方法 感觉kludgy,但您可以尝试添加destinationVIEwController.vIEw作为动画之前的子视图,然后当动画完成后,删除它并将其推回而不用动画.在过渡之前解决黑屏,但也可能不完美,这取决于您想要使用导航栏的内容,但也可能更接近:[sourceVIEwController.vIEw addSubvIEw:destinationVIEwController.vIEw];[destinationVIEwController.vIEw setFrame:sourceVIEwController.vIEw.window.frame];[destinationVIEwController.vIEw settransform:CGAffinetransformMakeScale(0.5,0.5)];[destinationVIEwController.vIEw setAlpha:1.0];[UIVIEw animateWithDuration:0.5 delay:0.0 options:UIVIEwAnimationCurveEaSEOut animations:^{ [destinationVIEwController.vIEw settransform:CGAffinetransformMakeScale(1.0,1.0)]; [destinationVIEwController.vIEw setAlpha:1.0]; } completion:^(BOol finished){ [destinationVIEwController.vIEw removeFromSupervIEw]; [sourceVIEwController.navigationController pushVIEwController:destinationVIEwController animated:NO]; }];
注意,有效的iOS 7,您将使用自定义转换.有关更多信息,请参阅WWDC 2013 Custom Transitions Using View Controllers.
例如,如果尝试使用导航控制器进行自定义转换,则第一个视图控制器将自己指定为导航控制器的代理:
self.navigationController.delegate = self;
然后,它将分别指定push和pop的自定义动画师:
- (ID<UIVIEwControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromVIEwController:(UIVIEwController *)fromVC toVIEwController:(UIVIEwController *)toVC{ if (operation == UINavigationControllerOperationPush) { return [[PushAnimator alloc] init]; } else { return [[PopAnimator alloc] init]; }}
那么你显然会实现这些动画师:
@interface PushAnimator : NSObject <UIVIEwControllerAnimatedTransitioning>@end@implementation PushAnimator- (NSTimeInterval)TransitionDuration:(ID <UIVIEwControllerContextTransitioning>)TransitionContext{ return 0.5;}- (voID)animateTransition:(ID<UIVIEwControllerContextTransitioning>)TransitionContext{ UIVIEwController* toVIEwController = [TransitionContext vIEwControllerForKey:UITransitionContextToVIEwControllerKey]; UIVIEwController* fromVIEwController = [TransitionContext vIEwControllerForKey:UITransitionContextFromVIEwControllerKey]; [[TransitionContext containerVIEw] addSubvIEw:toVIEwController.vIEw]; toVIEwController.vIEw.frame = fromVIEwController.vIEw.frame; toVIEwController.vIEw.transform = CGAffinetransformMakeScale(0.5,0.5); toVIEwController.vIEw.Alpha = 0.0; [UIVIEw animateWithDuration:[self TransitionDuration:TransitionContext] delay:0.0 options:0 animations:^{ toVIEwController.vIEw.transform = CGAffinetransformIDentity; toVIEwController.vIEw.Alpha = 1.0; } completion:^(BOol finished) { [fromVIEwController.vIEw removeFromSupervIEw]; [TransitionContext completeTransition:![TransitionContext TransitionWasCancelled]]; }];}@end
和
@interface PopAnimator : NSObject <UIVIEwControllerAnimatedTransitioning>@end@implementation PopAnimator- (NSTimeInterval)TransitionDuration:(ID <UIVIEwControllerContextTransitioning>)TransitionContext{ return 0.5;}- (voID)animateTransition:(ID<UIVIEwControllerContextTransitioning>)TransitionContext{ UIVIEwController* toVIEwController = [TransitionContext vIEwControllerForKey:UITransitionContextToVIEwControllerKey]; UIVIEwController* fromVIEwController = [TransitionContext vIEwControllerForKey:UITransitionContextFromVIEwControllerKey]; [[TransitionContext containerVIEw] insertSubvIEw:toVIEwController.vIEw belowSubvIEw:fromVIEwController.vIEw]; toVIEwController.vIEw.frame = fromVIEwController.vIEw.frame; [UIVIEw animateWithDuration:[self TransitionDuration:TransitionContext] delay:0.0 options:0 animations:^{ fromVIEwController.vIEw.transform = CGAffinetransformMakeScale(0.5,0.5); fromVIEwController.vIEw.Alpha = 0.0; } completion:^(BOol finished) { [fromVIEwController.vIEw removeFromSupervIEw]; [TransitionContext completeTransition:![TransitionContext TransitionWasCancelled]]; }];}@end总结
以上是内存溢出为你收集整理的ios – 自定义Segue动画全部内容,希望文章能够帮你解决ios – 自定义Segue动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)