iOS 7自定义转换问题
我试图在iPad上实现一些自定义转换,但我遇到了一些问题。由于旋转设备时,x、y坐标并不总是从iOS 7自定义转换问题,ios,uiviewanimationtransition,Ios,Uiviewanimationtransition,我试图在iPad上实现一些自定义转换,但我遇到了一些问题。由于旋转设备时,x、y坐标并不总是从transitionContext的containerView的左上角开始,因此我编写了以下方法 - (CGRect)rectForPresentedStateStart:(id<UIViewControllerContextTransitioning>)transitionContext { UIViewController *fromViewController = [trans
transitionContext
的containerView
的左上角开始,因此我编写了以下方法
- (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;
}
}
-(CGRect)rectForPresentedStateStart:(id)transitionContext
{
UIViewController*fromViewController=[transitionContext ViewControllerWorky:UITransitionContextFromViewControllerKey];
UIView*containerView=[transitionContext containerView];
开关(来自ViewController.interfaceOrientation)
{
案例UIInterfaceOrientation和scapeRight:
返回CGRectMake(0,containerView.bounds.size.height,
containerView.bounds.size.width,containerView.bounds.size.height*2/3);
案例UIInterfaceOrientation和scapeLeft:
返回CGRectMake(0,-containerView.bounds.size.height*2/3,
containerView.bounds.size.height,containerView.bounds.size.height*2/3);
案例UIInterfaceOrientation肖像向上向下:
返回CGRectMake(-containerView.bounds.size.width*2/3,0,
containerView.bounds.size.width*2/3,containerView.bounds.size.height);
案例UIInterfaceOrientation纵向:
返回CGRectMake(containerView.bounds.size.width,0,
containerView.bounds.size.width*2/3,containerView.bounds.size.height);
违约:
返回零;
}
}
-(CGRect)rectForPresentedStateEnd:(id)transitionContext
{
UIViewController*toViewController=[transitionContext ViewControllerWorky:UITransitionContextToViewControllerKey];
UIView*containerView=[transitionContext containerView];
开关(至ViewController.interfaceOrientation)
{
案例UIInterfaceOrientation和scapeRight:
返回CGRectOffset([self-rectForPresentedStateStart:transitionContext],0,-containerView.bounds.size.height*2/3);
案例UIInterfaceOrientation和scapeLeft:
返回cRectOffset([self-rectForPresentedStateStart:transitionContext],0,containerView.bounds.size.height*2/3);
案例UIInterfaceOrientation肖像向上向下:
返回CGRectOffset([self-rectForPresentedStateStart:transitionContext],containerView.bounds.size.width*2/3,0);
案例UIInterfaceOrientation纵向:
返回CGRectOffset([self-rectForPresentedStateStart:transitionContext],-containerView.bounds.size.width*2/3,0);
违约:
返回零;
}
}
在肖像模式和倒置模式下,一切似乎都很好。问题在于景观
ui接口方向和scapeleft
时,视图会在转换开始前消失一秒钟
ui界面方向和scaperight
时,我发现以下问题:导航栏变小,当过渡结束时,导航栏变为正常,如图所示
我不确定这些是苹果的bug还是我做错了什么,如果是,我该如何解决这些问题?我想,你的
containerView
是UIWindow
。所以它的边界是方向独立的,所以containerView.bounds.size.height
在纵向和横向上是相同的
如果我是对的,你需要在风景中使用宽度作为高度,高度作为宽度这肯定是一个苹果错误。为了演示动画,我使用了如下内容:
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
方法之后。仍然无法找出原因。我希望这将对您有所帮助@Spynet我尝试在我的表视图中更改它,但不幸的是,没有任何更改,它看起来仍然相同或有一些额外的行为……@Spynet看起来完全一样。当我使用AutoLayout时,它看起来也一样。你能再解释一下吗?你有两张表还是一张表,不完全一样。它不像一扇窗户。旋转时,轴不会停留在左上角。因此,一切都应该相应地进行调整。