我正在尝试在iPad上实现一些自定义转换,但我遇到了一些问题。由于x,y坐标并不总是从containerView
的{{1}}的左上角开始,当设备旋转时我写了以下方法
transitionContext
在纵向模式和颠倒过程中,一切似乎都能正常工作。问题出在景观上。
当设备方向为- (CGRect)rectForPresentedStateStart:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIView *containerView = [transitionContext containerView];
switch (fromViewController.interfaceOrientation)
{
case UIInterfaceOrientationLandscapeRight:
return CGRectMake(0, containerView.bounds.size.height,
containerView.bounds.size.width, containerView.bounds.size.height * 2 / 3);
case UIInterfaceOrientationLandscapeLeft:
return CGRectMake(0, - containerView.bounds.size.height * 2 / 3,
containerView.bounds.size.height, containerView.bounds.size.height * 2 / 3);
case UIInterfaceOrientationPortraitUpsideDown:
return CGRectMake(- containerView.bounds.size.width * 2 / 3, 0,
containerView.bounds.size.width * 2 / 3, containerView.bounds.size.height);
case UIInterfaceOrientationPortrait:
return CGRectMake(containerView.bounds.size.width, 0,
containerView.bounds.size.width * 2 / 3, containerView.bounds.size.height);
default:
return CGRectZero;
}
}
- (CGRect)rectForPresentedStateEnd:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *containerView = [transitionContext containerView];
switch (toViewController.interfaceOrientation)
{
case UIInterfaceOrientationLandscapeRight:
return CGRectOffset([self rectForPresentedStateStart:transitionContext], 0, - containerView.bounds.size.height * 2 / 3);
case UIInterfaceOrientationLandscapeLeft:
return CGRectOffset([self rectForPresentedStateStart:transitionContext], 0, containerView.bounds.size.height * 2 / 3);
case UIInterfaceOrientationPortraitUpsideDown:
return CGRectOffset([self rectForPresentedStateStart:transitionContext], containerView.bounds.size.width * 2 / 3, 0);
case UIInterfaceOrientationPortrait:
return CGRectOffset([self rectForPresentedStateStart:transitionContext], - containerView.bounds.size.width * 2 / 3, 0);
default:
return CGRectZero;
}
}
时,视图会在转换开始前消失一秒钟。
当设备方向为UIInterfaceOrientationLandscapeLeft
时,我遇到以下问题:导航栏较小,转换结束时会像图片一样转为正常
转换发生时导航栏出现问题
转换完成后
我不确定这些是苹果的错误还是我做错了什么?如果是,我该如何解决问题?
答案 0 :(得分:3)
这绝对是一个苹果虫。为了呈现动画,我正在使用这样的东西:
if (self.presenting) {
toViewController.view.frame = [self rectForPresentedStateStart:transitionContext];
[transitionContext.containerView addSubview:toViewController.view];
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
fromViewController.view.frame = [self rectForDismissedState:transitionContext];
toViewController.view.frame = [self rectForPresentedStateEnd:transitionContext];
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
如果添加视图([transitionContext.containerView addSubview:toViewController.view];
,导航控制器的问题就解决了
)animateWithDuration
方法之后。仍然无法弄清楚原因。
答案 1 :(得分:0)
我猜,您的containerView
是UIWindow
。所以它的界限与方向无关,因此containerView.bounds.size.height
在纵向和横向上是相同的。
如果我是对的,你需要使用宽度作为高度和高度作为横向宽度