我开发了一个应用程序,它使用 GPOrientationKit 支持纵向和横向。我按照以下链接来完成应用程序的所有页面以支持这两种方向。
我用 XIB 或 NIB 文件做了那个应用程序。现在,我正在开发一个带有 Storyboard的应用程序。我不知道如何制作支持 Storyboard两个方向的应用程序。 GOrientationKit 适用于 XIB 文件。但是我在 Storyboard中苦苦挣扎。我需要 Storyboard中的 GPOrientationKit 等功能。请帮助我做到这一点。
提前致谢。
最佳答案
只需将两个 subview 添加到您的 Controller 的主视图,例如纵向 View 和横向 View ,并在您的方向改变时在它们之间切换......我有这样的东西
在你的 viewWillAppear 方法中添加这个
-(void)viewDidAppear:(BOOL)animated{
if(UIDeviceOrientationIsPortrait(self.interfaceOrientation))
{
//Keep LAndscape View Hidden
self.portraitVIew.frame=self.view.frame;
[self.view addSubview:self.portraitVIew];
}else{
//Keep portrait View Hidden
self.landscapeView.frame=self.view.frame;
[self.view addSubview:self.landscapeView];
}
self.view.autoresizesSubviews = YES;
}
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(deviceOrientationDidChangeNotification:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
然后实现方法deviceOrientationDidChangeNotification例如
- (void)deviceOrientationDidChangeNotification:(NSNotification*)note
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if(UIDeviceOrientationIsLandscape(self.interfaceOrientation))
{
//Keep portrait View Hidden
NSLog(@"YUP THIS IS LANDSCAPE");
self.landscapeView.hidden=NO;
self.landscapeView.frame=self.view.frame;
[self.portraitVIew removeFromSuperview];
///self.landscapeView.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:self.landscapeView];
}else {
//Keep LAndscape View Hidden
self.landscapeView.hidden=YES;
self.portraitVIew.frame=self.view.frame;
NSLog(@"Portrait");
[self.view addSubview:self.portraitVIew];
}
}
关于ios - 在 iOS Interface Builder 中使用 StoryBoard 支持横向和纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24927213/