在不需要的视野时触发备用景观 [英] Alternate landscape triggered at unwanted view
问题描述
我有一个包含图像和tableview的视图控制器.通过此视图控制器,我将segue连接到了包含全屏图像的横向视图(当您从Apple侧向旋转股票应用程序以全屏查看图形时,使用了相同的想法.)
I have a view controller that contains an image and a tableview. From this view controller I connected a segue to a landscape view that contains the image in full screen (same idea used when you turn sideways the Stocks app from Apple to see the graph in full screen).
此segue通过以下方法调用:
This segue is called by the following method:
- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self performSegueWithIdentifier: @"toGraph" sender: self];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissViewControllerAnimated:YES completion:nil];
isShowingLandscapeView = NO;
}
}
此外,当iPhone处于纵向方向时,我还可以在桌面视图中向下钻几个级别.问题如下:在那些相应的级别上,当我将方向转到风景时,仍然会触发对风景视图的选择!...我该怎么做才能避免这种情况发生?我只想从包含图片的第一个视图转到横向模式.
Besides this, when the iphone is at portrait orientation, I can also drill-down the tableview a couple more levels. The problem is the following: at those consequent levels, the segue to the landscape view still gets triggered when I turn the orientation to landscape!... what can I do so that this does not happen? I am only interested in going to landscape mode from the first view which contains the image.
先谢谢您!
推荐答案
我不确定我是否正确解决了您的问题.导航控制器层次结构,您可以尝试以下操作.
I don't know for sure if I got your issue right.. but if you mean with "drill-down the table view" to go deeper in a navigation controller hierachy, you can try the following..
这就是我在(我认为)类似情况下所做的事情:
That's what I did in a (I think) similar situation:
AppDelegate:
AppDelegate:
在.h中:
@property (nonatomic) BOOL shouldAutorotate;
在.m中:
//在didFinishLaunchingWithOptions中:
// in didFinishLaunchingWithOptions:
self.shouldAutorotate = NO;
//仍在.m文件中
// Autorotation handling
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return self.shouldAutorotate ?
UIInterfaceOrientationMaskAllButUpsideDown :
UIInterfaceOrientationMaskPortrait;
}
导航控制器呈现人像控制器
Navigation Controller presenting Portrait Controller
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSUInteger)supportedInterfaceOrientations
{
if (self.selectedViewController)
return [self.selectedViewController supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate
{
return YES;
}
Portrait View Controller(这也是您所执行的非常类似的segue处理):
Portrait View Controller (here's also a very similar segue handling that you have):
在viewWillAppear中:
in viewWillAppear:
[(AppDelegate *)[[UIApplication sharedApplication] delegate] setShouldAutorotate:YES];
旋转处理:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Landscape View Controller(可能是全屏图像):
Landscape View Controller (probably your full screen image):
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
导航控制器层次结构中的更深层(仅需要肖像):
Deeper in the navigation controller hierachy (where only portrait is wanted):
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
看起来有些复杂,但这是唯一的方法,我设法使这些轮换功能在iOS5和6中都能正常工作.
Looks somehow complicated, but that was the only way, I managed to get those rotation things working properly in both iOS5 and 6.
这篇关于在不需要的视野时触发备用景观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!