创建自定义的Segue前有道 [英] PROPER way of creating Custom Segue

查看:187
本文介绍了创建自定义的Segue前有道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,是的,有数百个问题(和答案)如何执行自定义塞格斯。不过,我没有夸张,所有这些答案都是错的(50 +所有我见过的)!对不起,这听起来刺耳,但事实是,建议的答案都不给由于内置了苹果的过渡做同样的(正确的)结果(垂直盖等)。

Now, yes, there are hundreds of questions (and answers) of how to perform custom segues. However, and I'm no exaggerating, ALL of these answers are wrong (all 50+ I've seen)! Sorry, this might sound harsh, but the truth is, NONE of the suggested answers gives the same (correct) result as Apples built in transitions do (vertical cover etc.).

要更具体而言,这是提供预期的结果(与原木确认):

To be more specific, this is the result that's expected (confirmed with logs):


  1. Segue公司开始(增加以层次结构,调用 viewWillAppear中上destinationVC和 viewWillDisappear 上sourceVC并开始动画)。

  2. 作为整个期间进行动画

  3. Segue公司端(动画完成后,设置destinationVC作为当前VC,无论是在 viewDidAppear 堆栈或模态presented。调用上destinationVC和 viewDidDisappear 上sourceVC)。

  1. Segue begins (adds view to hierarchy, invokes viewWillAppear on destinationVC and viewWillDisappear on sourceVC and starts animation).
  2. animation is performed for the whole duration
  3. Segue ends (animation finished, sets the destinationVC as the current VC, either on stack or modally presented. Invokes viewDidAppear on destinationVC and viewDidDisappear on sourceVC).

在短:调用 viewWillAppear中/消失 - > 动画过渡 - > 调用 viewDidAppear /消失

In short: invoke viewWillAppear/Disappear -> animate transition -> invoke viewDidAppear/Disappear

使用苹果内置塞格斯,这是预期的行为,但不知何故没有一个灵魂,除了我有这个问题。很多版本甚至第一目的地添加视图作为子视图,动画然后重新将其删除,并呼吁

Using apples built-in segues, this is the expected behavior but somehow not a single soul except me have had issues with this. A lot of versions even add the destination-view as subview first, animates it then removes it again and calls

[srcVC presentModalViewController:destVC动画:NO];

or

[srcVC.navigationController pushViewController:destVC动画:NO];

造成视图的事件将各种随机顺序(同样的问题与CoreAnimations)的发送。

causing the view-events to be sent in all kinds of random order (same issue with CoreAnimations).

在我而言,我真正想要的是垂直盖转变点恢复(从上到下),与预期(如上图所示)EXACTLY发出的所有其他事件。

In my case, all I really want is the "Vertical Cover"-transition reverted (top to bottom), with all other events sent EXACTLY as expected (shown above).

所以,我只是认为各种丑陋的变通办法住(在做所谓的硬件codeD的方法我的任务,每当我需要他们等),或者是有一些隐藏的 正确在一个可重用的方式这样做的方法是什么?

So, am I just supposed to live with all kinds of ugly workarounds (doing my "tasks" in hard-coded methods called whenever I need them to etc.), or is there some hidden proper way of doing this in a reusable manner?

有趣的事情:即使苹果<一个href=\"https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomSegues/CreatingCustomSegues.html/\"相对=nofollow>建议你这样做了错误的方式,使它看起来像正确的方式,但不一致的结果相比,他们自己的方式......所以,我最好的猜测是,苹果在引擎盖下做到这一点和忘了给足够的灵活性,为客户执行相同的操作(大缺陷换句话说),或者说,我只是有些坏之旅,看到一些问题不存在...

Funny thing: Even apple suggest that you do it the "wrong" way, making it seem like the right way but with inconsistent outcome compared to their own ways… So my best guess is that apple do this under the hood, and forgot to give enough flexibility for clients to perform the same operations (big flaw in other words), or that I'm just on some bad trip and see some issue that doesn't exist…

推荐答案

好吧,这可能不是如何解决它定制塞格斯(继承UIStoryboardSegue)一个真正的答案,但它确实解决了一般的问题!

Okay, this might not be a true answer of how to solve it for custom segues (subclassing UIStoryboardSegue), but it does solve the general issue!

有关新功能的一些休闲阅读后,我偶然发现了一种新的方式做iOS7介绍ViewControllers之间进行自定义切换叫什么比自定义转换我想更多!
读到这里 和的这里或视频的这里

After some casual reading about new features, I stumbled upon a new way to do custom transitions between ViewControllers introduced in iOS7 called nothing more than "Custom Transitions" i guess! Read about it here and here, or video from WWDC here.

我刚刚蘸我的脚趾,但基本上它是一个新的,更贴近做过渡的系统的方式,并允许更好地控制=更好看的过渡。在由博客中提供的例子一眼后,我引用(GIT发现这里)我可以证实,最后,我们能够做的,它们的行为转变为一个希望他们与事件在预期的情况下被解雇了!

I've just dipped my toes, but basically it is a new, closer to the system way of doing transitions and allows for better control = better looking transitions. After glancing at the example provided by the blog I referenced (git found here) I can confirm that FINALLY, we are able to do transitions which behave as ONE EXPECTS THEM TO with events fired at the expected occasions!

由于我刚刚读到它,我不能给一个彻底的解释还,但检查出的链接:)

Since I'm just reading about it I can't give a thorough explanation yet, but check out the links :)

请注意:这也许不应该完全取代定制塞格斯,但能以类似的方式使用(检查例子),所以如果你需要一点额外的花哨的过渡,这绝对是它的外观走的路!基本上你设置塞格斯在故事板,并在挂钩正确的过渡代表了 prepareForSegue: -method

Note: This is maybe not supposed to completely replace custom segues, but can be used in a similar fashion (check examples) so if you need that little extra fancy transition, this is definitely the way to go by the looks of it! Basically you setup segues in the storyboard, and hook up the correct transition-delegates in the prepareForSegue:-method.

这篇关于创建自定义的Segue前有道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆