我有一个故事板,它有一个标签栏控制器。当设备旋转时,我想移动到不同的屏幕,即不横向显示相同的布局,而是显示完全不同的内容。
在iOS 5中,我在UITabBarControllerDelegate中使用以下代码实现了这一目标
。- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
[self performSegueWithIdentifier: @"toGraph" sender: self];
}
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
在 iOS 6 中,不再调用此方法。 我能看到的所有方法都在旋转视图时处理,但在设备旋转时不处理。
提前谢谢。
所以我真的不应该寻找视图旋转,而是设备旋转。在发现UIDevice类后,我能够使用AlternateViews示例代码(只需在文档管理器中搜索AlternateViews)来获得我需要的一切。
- (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 中的自动旋转已更改。这是苹果开发论坛上关于这个问题的一个帖子:https://devforums.apple.com/thread/166544?tstart=30
以下是更多线程:http://www.buzztouch.com/forum/thread.php?tid=41ED2FC151397D4AD4A5A60¤tPage=1
https://www.buzztouch.com/forum/thread.php?fid=B35F4D4F5EF6B293A717EB5&tid=B35F4D4F5EF6B293A717EB5
这些与您的问题最相关的帖子似乎如下:
让它工作...对于选项卡式应用,请替换应用委托中的以下行: [self.window addSubview:[self.rootApp.rootTabBarController view]];
有了这个: [self.window.rootViewController = self.rootApp.rootTabBarController view];
要获取非选项卡式应用程序,请替换此行: [self.window addSubview:[self.rootApp.rootNavController view]];
有了这个: [self.window.rootViewController = self.rootApp.rootNavController view];