【发布时间】:2016-04-20 22:34:07
【问题描述】:
我有管理自定义转换的对象:
@interface NavigationManager : NSObject <UIViewControllerAnimatedTransitioning>
-(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext;
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext;
@property (nonatomic, assign) NSTimeInterval presentationDuration;
@property (nonatomic, assign) NSTimeInterval dismissalDuration;
@property (nonatomic, assign) BOOL isPresenting;
@end
@interface NavigationManager()
@property (nonatomic, strong) id<UIViewControllerContextTransitioning> transitionContext;
@end
@implementation NavigationManager
@synthesize presentationDuration, dismissalDuration, isPresenting;
-(id)init{
self = [super init];
if(self){
self.presentationDuration = 1.0;
self.dismissalDuration = 0.5;
}
return self;
}
-(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{
return self.isPresenting ? self.presentationDuration : self.dismissalDuration;
}
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{
self.transitionContext = transitionContext;
if(self.isPresenting){
[self executePresentation:transitionContext];
}
else{
[self executeDismiss:transitionContext];
}
}
...
@end
在应该处理实现转换的类中:
@interface ViewController : UIViewController <UIViewControllerTransitioningDelegate>
@property (nonatomic, strong) NavigationManager navigationManager;
..
@end
@implementation
...
//这里我正在导航到新的 UIViewController
- (void)navigateToNewScreen
{
DetailedNewsController *secVC = [[DetailedNewsController alloc] init];
secVC.fullDescription = fullDescription;
secVC.headerImage = a.imageView.image;
self.transitioningDelegate = self;
[self.navigationController pushViewController:secVC animated:YES];
}
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source
{
self.animationController.isPresenting = YES;
return self.animationController;
}
- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
self.animationController.isPresenting = NO;
return self.animationManager;
}
@end
执行默认的过渡动画。导航后也不显示导航控制器栏。
更新:
我在 AppDelegate 中创建 UINavigationController 的方式存在问题:
firstVC = [[ViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:firstVC];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor blackColor];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
【问题讨论】:
-
我从来没有为推送做过自定义过渡,但不应该是
secVC.transitioningDelegate = self;吗? -
改为:secVC.transitioningDelegate = self; secVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:secVC 动画:YES 完成:nil];它有效。但是导航栏是隐藏的
-
检查我的答案,让我知道它是否有效
标签: ios iphone uiviewanimationtransition