自定义 Segue 推送/弹出 UIViewController

发布于 2024-12-29 04:07:35 字数 488 浏览 4 评论 0原文

我正在尝试将类似 iBooks 的翻转过渡实现为故事板。 Segue 应该推动 resp。将 destinationViewController 弹出到 UINavigationControllers 堆栈中/从 UINavigationControllers 堆栈中弹出。

我可以在我的 segues perform 方法中推送视图控制器,但无法弹出。当我在创建翻转动画后弹出控制器时,动画不会运行,并且它的回调 - 应该执行 [[UIApplication shareApplication] endIgnoringInteractionEvents] 永远不会被调用,并且我的应用程序结果死了。

因此,我尝试在 animationDidStop:anim:flag 委托方法中推送/弹出,但在标志设置为 true 的情况下它永远不会被调用。

我假设在调用委托方法之前,segue 已被释放。我还能做什么?

I'm trying to implement an iBooks-like flip transition as a storyboard. The segue should push resp. pop the destinationViewController onto/from the UINavigationControllers stack.

I can push viewcontrollers in my segues perform method but I am not able to pop. When I pop the controller right after creating my flip animation the animation does not run and its callback - that should perform [[UIApplication sharedApplication] endIgnoringInteractionEvents] gets never called and my App results dead.

So I tried to push/pop in the animationDidStop:anim:flag delegate method but it never gets called with the flag set to true.

I assume that the segue is deallocated before the delegate method gets called. What else could I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回眸一笑 2025-01-05 04:07:35

如果我完全误解了这个问题,请原谅我,但看起来您只想在两个视图控制器之间来回进行基本的水平翻转。即使您已经弄清楚了这一点,也许它会对其他有相同问题的人有所帮助。

(1) 在故事板(具有 ViewController A 和 B)中创建从 A 到 B 的 Modal Segue。为其指定一个标识符 (showViewControllerB) 并选择 Transition:Flip Horizo​​ntal。

我们设置协议和委托:

(2a) 在 ViewControllerB.h 中添加@interface:

@class ViewControllerB;

@protocol ViewControllerBDelegate
    - (void)viewControllerBDidFinish:(ViewControllerB *)controller;
@end

(2b) 将委托添加为属性:

@property (weak, nonatomic) id <ViewControllerBDelegate> delegate;

(3a) 在 ViewControllerB.m 中综合:

@synthesize delegate;

(3b) 以及在要翻转的方法中委托:

- (IBAction)flipBack:(id)sender
{
    [self.delegate viewControllerBDidFinish:self];
}

(4) 在 ViewControllerA.h 中添加在最顶部的 #import "ViewControllerB.h" 和 @interface 的末尾

(5a) 在ViewControllerA.m中添加符合协议的方法:

- (void)viewControllerBDidFinish:(ViewControllerB *)controller
{
    [self dismissModalViewControllerAnimated:YES];
}

(5b) 然后将其设置为prepareForSegue中的委托:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showViewControllerB"]) {
        [[segue destinationViewController] setDelegate:self];
    }
}

我希望这能回答您的问题。如果我误解了,请告诉我。

Forgive me if I am completely misunderstanding this question, but it seems like you just want to do a basic horizontal flip back and forth between two view controllers. And even if you've already figured this out, maybe it will help anyone else who has the same question.

(1) In your storyboard (that has ViewController A & B) create a Modal Segue from A to B. Give it an identifier (showViewControllerB) and choose Transition:Flip Horizontal.

We set up the protocol and delegates:

(2a) In ViewControllerB.h add above @interface:

@class ViewControllerB;

@protocol ViewControllerBDelegate
    - (void)viewControllerBDidFinish:(ViewControllerB *)controller;
@end

(2b) Add the delegate as a property:

@property (weak, nonatomic) id <ViewControllerBDelegate> delegate;

(3a) In ViewControllerB.m synthesize:

@synthesize delegate;

(3b) And delegate in the method to flip back:

- (IBAction)flipBack:(id)sender
{
    [self.delegate viewControllerBDidFinish:self];
}

(4) In ViewControllerA.h add at the very top #import "ViewControllerB.h" and on the end of @interface <ViewControllerBDelegate>

(5a) In ViewControllerA.m add the method to conform to the protocol:

- (void)viewControllerBDidFinish:(ViewControllerB *)controller
{
    [self dismissModalViewControllerAnimated:YES];
}

(5b) Then set it as the delegate in prepareForSegue:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showViewControllerB"]) {
        [[segue destinationViewController] setDelegate:self];
    }
}

I hope this answers your question. If I misunderstood, just let me know.

行雁书 2025-01-05 04:07:35

你的问题有点令人困惑,因为混合了弹出、推、翻转和后空翻。我不确定人工智能是否可以回答你的问题,但我可以告诉你我做了什么。

如果我将 viewController 推入导航控制器堆栈并将 Storyboard Segue Style 设置为 Push,它将从右到左推入视图。将出现一个后退按钮,并在其中显示presentingViewController 的标题。

如果我将 Storyboard Segue Style 设置为 Modal,我可以将 Transition 设置为水平翻转(这似乎就是您想要的)。但随后不会出现后退按钮。在presentedViewController中,我通过以下方式关闭视图:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

它将通过右翻转将第二个视图翻转回来。

但这是肮脏的解决方案,苹果不推荐。

http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ManagingDataFlowBetweenViewControllers/ManagingDataFlowBetweenViewControllers.html#//apple_ref/doc/uid/TP40007457-CH8-SW9

卢克·杜伯特给了您有一个如何实现委托的示例。

Your question is a bit confusing as so mingle pop, push, flip and backflip. I´m not sure if ai can answer your question, but i can tell what i did.

If i push a viewController into the navigation controller stack and set the Storyboard Segue Style to Push, it will be pushed into the view from right to left. A back button appears and shows the title of the presentingViewController in it.

If i set the Storyboard Segue Style to Modal i can set the Transition to Flip Horizontal (what seems to be what you want). But then no Back Button will appear. In the presentedViewController i dismiss the view with:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

It will flip the second view back with a right flip.

But this is the dirty solution and it is not recommended by apple.

http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ManagingDataFlowBetweenViewControllers/ManagingDataFlowBetweenViewControllers.html#//apple_ref/doc/uid/TP40007457-CH8-SW9

Luke Dubert gave you an example how to implement the delegate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文