objective-c - 用 Storyboard反转自定义 Segue

标签 objective-c ios storyboard reverse segue

我有一个自定义的 segue 动画,它在将新的 View Controller 插入堆栈时发生。然而,当弹出带有所述自定义 segue 的 View Controller 时,会发生默认的导航 Controller 动画(即,当前 View Controller 向右动画,而父 View Controller 从左边缘在屏幕上平移)。

所以我的问题是:有没有一种方法可以编写自定义的 pop segue 动画,该动画在从堆栈中弹出 View Controller 时发生?

编辑(解决方案):

我最终定义了一个类似于所选答案的自定义转场。在 Storyboard 中,我将一个自定义转场从 subview Controller 拖回到其父 View Controller ,给它一个标识符,并将新编写的反向转场作为其类。是的,我意识到它实际上与模态转换相同。客户要求使这种疯狂成为必要,因此在任何人发表评论之前,请理解我知道在正常情况下不应该这样做。

- (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 时。在属性检查器中使用选择或输入新的新 segue 类。

//
//  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

如果您只想弹出一个级别的更改,请使用此自定义转场:

//  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];
}

@结束

关于objective-c - 用 Storyboard反转自定义 Segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9316233/

相关文章:

iphone - 在 NSThread 中使用 Singleton 同步数组

c# - 如何在 ScaleTransform 动画后重置控件

ipad - 如何在ios8中的ipad上使用通用应用程序的自适应层但按钮大小不同?

ios - 如何在 Objective C 中以编程方式设置 Root View Controller ?

iOS 从云存储中选择图像

ios - 如何移动 MKMapView 的中心,以便默认位置图标转到底部中心

ios - 当应用程序激活时刷新 Parse.com 数据

ios - 以编程方式选择选项卡自定义选项卡栏ios

ios - iOS 应用程序的 SSL 证书

swift - WatchKit:每当调用自定义 WKInterfaceButton 类上的函数时,都会因 exc_bad_access 失败