gpt4 book ai didi

objective-c - 在 iOS7 上使用 UINavigationControllerDelegate 实现上/下滑动过渡

转载 作者:搜寻专家 更新时间:2023-10-30 19:57:44 24 4
gpt4 key购买 nike

我花了一些时间尝试整理 iOS 7 中可用的自定义过渡动画。根据 this question , UINavigationControllerDelegate 是要走的路。

但是,没有示例或文档描述如何最好地处理 iOS7 中的简单垂直过渡。 (有一个 plethora of other transition styles using UINavigationControllerDelegate ,但没有一个像上下滑动 View 一样简单——还有其他建议只修改 View 位置,但这似乎是一个俗气的技巧?)。还有others too that go as far back to 2011 ,但他们显然没有使用 UINavigationControllerDelegate

Can anyone provide a basic working implementation of a simple slide up/down transition using UINavigationControllerDelegate?

免责声明:我很乐意提供代码,但由于还没有任何代码可以发布...不过我确实使用 jQuery 创建了一个简单的示例来展示我正在努力实现的目标。

检查 fiddle here

最佳答案

there are others that suggest just modifying the view position, but that seems like a tacky hack

不,这不是一个俗气的黑客。那就是你要做的。自定义过渡动画只是意味着您负责将新 View 带入场景中——前提是它最终出现在正确的位置。因此,从底部对其进行动画处理的方法很简单,就是将其放置在底部并将其向上移动到位。

例如(几乎直接取 self 书中的示例代码):

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
// boilerplate
UIViewController* vc1 =
[transitionContext
viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController* vc2 =
[transitionContext
viewControllerForKey:UITransitionContextToViewControllerKey];
UIView* con = [transitionContext containerView];
CGRect r1start = [transitionContext initialFrameForViewController:vc1];
CGRect r2end = [transitionContext finalFrameForViewController:vc2];
UIView* v1 = vc1.view;
UIView* v2 = vc2.view;
// end boilerplate

CGRect r = r2end;
r.origin.y += r.size.height; // start at the bottom...
v2.frame = r;
[con addSubview:v2];

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[UIView animateWithDuration:0.4 animations:^{
v2.frame = r2end; // ... and move up into place
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}];
}

该代码改编 self 在 https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch06p292customAnimation1/ch19p620customAnimation1/AppDelegate.m 的示例该示例几乎与您所描述的完全相同,只是它用于选项卡 Controller 而不是导航 Controller ,并且它来自侧面而不是底部。但原理是完全一样的。

关于objective-c - 在 iOS7 上使用 UINavigationControllerDelegate 实现上/下滑动过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21541080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com