ale*_*ash 5 uiviewanimationtransition ios
我正在尝试在 iPad 上实现一些自定义转换,但我遇到了一些问题。由于X,Y坐标不总是在左上角开始containerView的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;
}
}
Run Code Online (Sandbox Code Playgroud)
在纵向模式和颠倒一切似乎工作正常。问题出在景观上。
当设备方向为 时UIInterfaceOrientationLandscapeLeft,视图会在过渡开始前消失一秒钟。
当设备方向为时,UIInterfaceOrientationLandscapeRight我遇到以下问题:导航栏变小并在过渡结束时变为正常,如图片所示

发生转换时导航栏出现问题

过渡完成后
我不确定这些是来自苹果的错误还是我做错了什么,如果是这样,我该如何解决这些问题?
这绝对是苹果的 bug。为了呈现动画,我使用的是这样的东西:
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];
}];
}
Run Code Online (Sandbox Code Playgroud)
[transitionContext.containerView addSubview:toViewController.view];
如果我在方法后面添加视图 ( ),导航控制器的问题就可以解决 animateWithDuration。仍然不明白为什么。
| 归档时间: |
|
| 查看次数: |
514 次 |
| 最近记录: |