题
我有一个标签栏控制器的故事板。当设备旋转时,我想移动到不同的屏幕,即不显示相同的布局侧向但显示完全不同的东西。
在iOS 5中,我在uitabbarcontrollerdelegate中使用以下代码进行了此操作
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
[self performSegueWithIdentifier: @"toGraph" sender: self];
}
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
.
在iOS中,不再调用此方法。我可以看到何时旋转视图旋转时,我可以看到所有的方法,但不是旋转设备时。
提前感谢。
解决方案
所以真的我不应该寻找查看旋转,而是一个设备旋转。在发现Uidevice类后,我能够使用备用视图示例代码(仅在文档管理器中搜索备用视图)以获取我所需的一切。
.- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.delegate = self;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
// We must add a delay here, otherwise we'll swap in the new view
// too quickly and we'll get an animation glitch
[self performSelector:@selector(showGraphs) withObject:nil afterDelay:0];
}
- (void)showGraphs
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self performSegueWithIdentifier: @"toGraph" sender: self];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
其他提示
自动移动在iOS 6中发生了变化。这是Apple Dev论坛上的一个线程问题: https://devforums.apple.com/thread/166544?tstart=30
这里有一些更多的线程: http://www.buzztouch.com/forum/thread.php?tid= 41ED2FC151397D4AD4A5A60& CurrentPage= 1
这些来自这些问题的最相关的帖子似乎是以下内容:
搞定工作...对于选项卡式应用程序,请在appdelegate中替换此行: [self.window addsubview:[self.rootapp.roottabbarcontroller视图]];
与此: [self.window.rootviewController= self.rootapp.roottabbarController视图];
并获取非标签应用程序,替换此行: [self.window addsubview:[self.rootapp.rootnavcontroller视图]];
与此: [self.window.rootviewController= self.rootapp.rootnavcontroller视图];