ios:横向模式下两个viewcontrollers之间的自定义Segue [英] ios: Custom Segue between two viewcontrollers in landscape mode

查看:82
本文介绍了ios:横向模式下两个viewcontrollers之间的自定义Segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个UIViewControllers,它们包含在navigatoin视图控制器中,并且都处于横向模式。我想在两个uiviewcontroller之间切换而没有像push这样的动画。因此,如果用户在第一个viewcontroller中单击一个按钮,我会在这两个之间执行自定义segue。

I have two UIViewControllers that are contained in a navigatoin view controller and both in landscape mode. I want to switch between two uiviewcontroller without have an animation like push. Therefore I perform a custom segue between these two if the user clicks in the first viewcontroller a button.

#import <Foundation/Foundation.h>
#import "AppDelegate.h"

@class AppDelegate;

@interface NonAnimatedSegue : UIStoryboardSegue {

}

@property (nonatomic,assign) AppDelegate* appDelegate;

@end

这就是实施:

#import "NonAnimatedSegue.h"

@implementation NonAnimatedSegue

@synthesize appDelegate = _appDelegate;

-(void) perform{
    self.appDelegate = [[UIApplication sharedApplication] delegate];
    UIViewController *srcViewController = (UIViewController *) self.sourceViewController;
    UIViewController *destViewController = (UIViewController *) self.destinationViewController;
[srcViewController.view removeFromSuperview];
[self.appDelegate.window addSubview:destViewController.view];
self.appDelegate.window.rootViewController=destViewController;
}

@end

在故事板中,我切换到自定义segue,实际上它工作正常。唯一的问题是第二个uiviewcontroller不是以横向模式显示,而是以protrait显示。如果我删除自定义segue并用push segue替换它,那么一切正常,第二个viewcontroller以横向模式显示。

In the storyboard I switched to custom segue and actually it works fine. The only problem is that the second uiviewcontroller is not displayed in landscape mode but in protrait. If I remove the custom segue and replace it with a push segue then everything works fine, the second viewcontroller is displayed in landscape mode.

那么如果我使用自定义segue,我还需要做什么才能使第二个viewcontroller也在横向视图中?

So what do I have to do such that the second viewcontroller is also in landscape view if I use my custom segue?

推荐答案

上面的代码不起作用,因为destinationViewController无法自己从UIInterfaceOrientation接收更新。它通过它的容器视图控制器(导航控制器)接收这些更新。为了使自定义segue正常工作,我们需要通过导航控制器转换到新视图。

The code above doesn't work because the destinationViewController cannot receive updates from UIInterfaceOrientation on it's own. It receives those updates through it's "Container View Controller" (the Navigation Controller). To get the custom segue to work properly, we need to transition to the new view through the Navigation Controller.

-(void) perform{
    [[[self sourceViewController] navigationController] pushViewController:[self destinationViewController] animated:NO];
}

这篇关于ios:横向模式下两个viewcontrollers之间的自定义Segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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