我有三个视图控制器,像Snapchat一样排列。主要嵌入在UINavigationController中,左侧是一个视图控制器,右侧是一个视图控制器。 转换效果很好,左/右动画。但是当你切换到相机旁边的控制器或反之亦然时,相机将在自定义segue上保持可见(不是黑色)。使用MINE,如果我将第二个视图控制器推到堆栈上,当我希望它保持完全可见时,第一个视图控制器似乎渐渐变为黑色。我猜我必须在我的自定义segue中改变一些东西。
@implementation toTheRight
- (void) perform{
UIViewController *sourceViewController = (UIViewController *)self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *)self.destinationViewController;
CATransition *transition = [CATransition animation];
transition.duration = .5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[sourceViewController.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[sourceViewController.navigationController pushViewController:destinationViewController animated:NO];
}
答案 0 :(得分:0)
取自这两个项目,然后修改CustomSegue和CustomUnwindSegue作为示例。 https://github.com/soleares/SOLPresentingFun https://github.com/Phillipus/CustomSegue
CustomSegue.m
#import "CustomSegue.h"
#import "SOLSlideTransitionAnimator.h"
@interface CustomSegue()<UIViewControllerTransitioningDelegate>
@property (nonatomic,strong) SOLSlideTransitionAnimator* animator;
@end
@implementation CustomSegue
- (void)perform {
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destinationViewController = self.destinationViewController;
destinationViewController.transitioningDelegate = self;
destinationViewController.modalPresentationStyle = UIModalPresentationCustom;
[sourceViewController presentViewController:destinationViewController animated:YES completion:nil];
}
/*
Called when presenting a view controller that has a transitioningDelegate
*/
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source
{
self.animator.appearing = YES;
return self.animator;
}
-(SOLSlideTransitionAnimator*) animator
{
if(!_animator)
{
_animator = [[SOLSlideTransitionAnimator alloc] init];
_animator.appearing = NO;
_animator.duration = 0.35;
_animator.edge = SOLEdgeRight;
}
return _animator;
}
@end
CustomUnwindSegue.m
@interface CustomUnwindSegue()<UIViewControllerTransitioningDelegate>
@property (nonatomic,strong) SOLSlideTransitionAnimator* animator;
@end
#import "CustomUnwindSegue.h"
#import "SOLSlideTransitionAnimator.h"
@implementation CustomUnwindSegue
- (void)perform {
UIViewController *sourceViewController = self.sourceViewController;
sourceViewController.transitioningDelegate = self;
sourceViewController.modalPresentationStyle = UIModalPresentationCustom;
[sourceViewController dismissViewControllerAnimated:YES completion:nil];
}
-(SOLSlideTransitionAnimator*) animator
{
if(!_animator)
{
_animator = [[SOLSlideTransitionAnimator alloc] init];
_animator.appearing = NO;
_animator.duration = 0.35;
_animator.edge = SOLEdgeRight;
}
return _animator;
}
/*
Called when dismissing a view controller that has a transitioningDelegate
*/
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
self.animator.appearing = NO;
return self.animator;
}
@end