本文介绍了通过故事板逆转自定义搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个新的视图控制器推入堆栈时会出现自定义的segue动画。然而,当弹出与所述自定义segue一起呈现的视图控制器时,默认导航控制器动画发生(即,当父视图控制器从左边缘在屏幕上转换时,当前视图控制器向右动画)。

I have a custom segue animation that occurs when pushing a new view controller onto the stack. When popping the view controller that was presented with said custom segue, however, the default navigation controller animation happens (that is, the current view controller animates to the right while the parent view controller translates on-screen from the left edge).

所以我的问题是:有没有办法编写一个自定义的pop segue动画,当从视图控制器弹出堆栈时会发生这种情况?

So my question is this: is there a way to write a custom pop segue animation which happens when popping a view controller off the stack?

编辑(解决方案):

我最终定义了类似的自定义segue选定的答案。在Storyboard中,我将一个自定义segue从子视图控制器拖回到它的父级,给它一个标识符,新写的反向segue作为它的类。是的,我意识到它几乎与模态转换相同。客户要求需要这种疯狂,所以在任何人评论之前,要明白我知道在正常情况下不应该这样做。

I ended up defining a custom segue similar to the selected answer. In the Storyboard, I dragged a custom segue from the child view controller back to its parent, gave it an identifier and the newly written reverse segue as its class. Yes, I realize it is virtually identical to a modal transition. Client requirements necessitated this madness, so before anyone comments, understand that I know one shouldn't have to do this under normal circumstances.

- (void)perform {
  UIViewController *src = (UIViewController *)self.sourceViewController;
  UIViewController *dest = (UIViewController *)self.destinationViewController;

  [UIView animateWithDuration:0.3 animations:^{
    CGRect f = src.view.frame;
    f.origin.y = f.size.height;
    src.view.frame = f;

  } completion:^(BOOL finished){
    src.view.alpha = 0;
    [src.navigationController popViewControllerAnimated:NO];
  }];
}


推荐答案

是的。这是一个我弹出顶级的例子。在Storyboard中创建segue时。使用select或在属性检查器中输入新的新segue类。

Yes. Here is an example where I pop to the top level. When your create the segue in Storyboard. Use select or enter the new new segue class in the attributes inspector.

//
//  FlipTopPop.h

#import <UIKit/UIKit.h>


@interface FlipTopPopToRoot : UIStoryboardSegue

@end

//  FlipTopPop.m

#import "FlipTopPopToRoot.h"

@implementation FlipTopPopToRoot

- (void) perform {

    UIViewController *src = (UIViewController *) self.sourceViewController;
    [UIView transitionWithView:src.navigationController.view duration:0.5
                   options:UIViewAnimationOptionTransitionFlipFromBottom
                animations:^{
                    [src.navigationController popToViewController:[src.navigationController.viewControllers objectAtIndex:0] animated:NO];;
                }
                    completion:NULL];
}

@end

如果你想弹出只需一个级别更改即可使用此自定义segue:

If you want to pop up just one level change use this custom segue:

//  PopSegue.h

#import <UIKit/UIKit.h>

@interface PopSegue : UIStoryboardSegue

@end

//  PopSegue.m

#import "PopSegue.h"

@implementation PopSegue

- (void) perform {

    UIViewController *src = (UIViewController *) self.sourceViewController;
    [src.navigationController popViewControllerAnimated:YES];
}

@end

这篇关于通过故事板逆转自定义搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 04:03
查看更多