我试图在iOS 7中构建自定义转换。转换很顺利,但是当转换上下文完成转换时,模态屏幕完全从视图中消失。我已经完成了几个教程,但我不知道自己做错了什么。另外,如果我没有打电话给#34;完成过渡"然后视图停留,但不会收到任何触摸事件。我检查了Reveal App,没有看到它的顶部。有什么想法吗?
以下是我启动转换的方法
- (IBAction)settingsButtonClicked:(id)sender
{
UINavigationController *navigationController =[[self storyboard] instantiateViewControllerWithIdentifier:@"SettingsNavigationViewController"];
navigationController.transitioningDelegate = self;
[self presentViewController:navigationController animated:YES completion:nil];
}
以下是自定义转换的代码:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *containerView = [transitionContext containerView];
[containerView addSubview:toViewController.view];
CGRect sourceRect = [transitionContext initialFrameForViewController:fromViewController];
CGRect initialTargetFrame = [transitionContext initialFrameForViewController:toViewController];
CGRect initialFrame = CGRectMake(sourceRect.size.width + initialTargetFrame.size.width, 0, initialTargetFrame.size.width, initialTargetFrame.size.height);
CGPoint destinationPoint = CGPointMake(sourceRect.size.width - 500, 0);
CGAffineTransform translate = CGAffineTransformMakeTranslation(initialFrame.origin.x, initialFrame.origin.y);
toViewController.view.transform = translate;
[UIView animateWithDuration:PRESENT_DURATION delay:0 options:UIViewAnimationOptionCurveEaseOut
animations:^{
toViewController.view.transform = CGAffineTransformMakeTranslation(destinationPoint.x, destinationPoint.y);
}
completion:^(BOOL completed) {
if (completed) {
[transitionContext completeTransition:!transitionContext.transitionWasCancelled];
}
}];
}
答案 0 :(得分:0)
所以我发现了我做错了什么。当我应该在导航控制器本身上设置它时,我正在将视频控制器上的modalPresentationStyle更改为自定义在弹出到导航控制器上的视图控制器上。我将此行添加到上面的settingsButtonClicked方法中,并且它正常工作。
navigationController.modalPresentationStyle = UIModalPresentationCustom;