[英]How to load a new view upon orientation change - iOS SDK xcode Interface builder
因此,我正在开发基于视图的应用程序,并且有一个我想以横向模式启动的应用程序(尚未完全了解如何执行该操作,因为在plist文件中,“初始设备方向”不是一个选项,因为我假设它曾经是,从人们所说的开始(我是这个应用程序开发人员的新手)。
无论如何,当我旋转到“人像”时,我想切换到一个全新的视图,当我旋转“人像”时,又想切换到另一个新视图。 到目前为止,我已经将View2Viewcontroller。(h + m)添加到了我的类中,还将View2.xib添加到了我的资源中。
我有以下代码:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if((fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight))
{
// Load the view controller I want to display in portrait mode...
}
}
但是我不太确定如何加载视图控制器,甚至不知道将这些代码放在哪里。
我建议您使用.nibv文件,最好了解如何通过代码初始化视图。 无论如何,您需要什么。
[[viewController alloc] initWithNibName:@"viewController" bundle:[NSBundle mainBundle]];
在代码中,您可以通过此代码在没有nib文件的情况下执行相同的操作
CGRect rect = [[UIScreen mainScreen] bounds];
//create a full-screen window
window = [[UIWindow alloc] initWithFrame:rect];
//create our view controller and add its view to the window
viewController = [ViewController new];
[window addSubview:[viewController view]];
[window makeKeyandVisible];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.