在我的应用程序中,我有多个视图,一些视图需要支持纵向和横向,而其他视图只需要支持纵向.因此,在项目摘要中,我已经选择了所有方向.
以下代码用于在iOS 6之前禁用给定视图控制器上的横向模式:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Run Code Online (Sandbox Code Playgroud)
由于在iOS6中不推荐使用shouldAutorotateToInterfaceOrientation,我将以上内容替换为:
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMask.Portrait;
}
Run Code Online (Sandbox Code Playgroud)
当视图出现时我会正确调用此方法(我可以设置断点以确保这一点),但是界面仍然会旋转到横向模式,而不管我是否仅为纵向模式返回蒙版.我究竟做错了什么?
似乎目前无法构建一个每个视图具有不同方向要求的应用程序.它似乎只遵循项目摘要中指定的方向.
我一直在网上寻找解决方案,但一无所获.我正在尝试使我的iOS 5应用iOS 6兼容.我无法让定位的东西正常工作.我无法检测到旋转何时发生.这是我正在尝试的代码:
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
// pre-iOS 6 support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
Run Code Online (Sandbox Code Playgroud)
新的supportedInterfaceOrientation:方法被调用就好了.但是,shouldAutorotate方法不会触发.我需要在旋转时进行一些图像交换,但我无法得到旋转即将发生的任何迹象.
提前致谢.
In iOS 6 shouldAutorotateToInterfaceOrientation没有用,但它在iOS 5.0或中工作正常5.1.
我应该需要改变什么iOS 6.这是我的代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if([[[SampleApplicationAppDelegate instance].callInfoDictionary valueForKey:IS_CHAT] isEqualToString:NO_RESPONSE])
{
int nAngle = 0;
BOOL bRet = NO;
switch (interfaceOrientation) {
case UIInterfaceOrientationPortrait:
nAngle = 90;
bRet = YES;
NSLog(@".......Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
NSLog(@"Preview = %f %f",_previewCamera.frame.size.width,_previewCamera.frame.size.height);
break;
case UIInterfaceOrientationPortraitUpsideDown:
nAngle = 270;
bRet = YES;
_previewCamera.transform = CGAffineTransformMakeRotation(M_PI_2);
break;
case UIInterfaceOrientationLandscapeLeft:
nAngle = 0;
bRet = YES;
//_previewCamera.transform = CGAffineTransformMakeRotation(M_PI*1.5);
break;
case UIInterfaceOrientationLandscapeRight:
nAngle …Run Code Online (Sandbox Code Playgroud) 我有一个iPhone应用程序我正在更新到iOS 6有旋转问题.我有UITabBarController16岁UINavigationCotrollers.大多数子视图可以在纵向或横向上工作,但其中一些只是纵向.对于iOS 6,它们不应该旋转.
我尝试将supportedInterfaceOrienationstabBarController 子类化为返回当前navigationController的选定viewController:
- (NSUInteger)supportedInterfaceOrientations{
UINavigationController *navController = (UINavigationController *)self.selectedViewController;
return [navController.visibleViewController supportedInterfaceOrientations];
}
Run Code Online (Sandbox Code Playgroud)
这让我更接近.视图控制器在可见时不会旋转到位置,但如果我处于横向和切换选项卡中,即使不支持,新选项卡也将处于横向状态.
理想情况下,应用程序仅在当前可见视图控制器的支持方向上.有任何想法吗?
rotation uitabbarcontroller orientation uinavigationcontroller ios6
任何人都可以确认,为了支持iOS 6和iOS 5,没有必要添加新的iOS 6自动旋转方法,因为如果您还在实施iOS 5方法,那么Apple文档会建议完全忽略这些方法吗?
特别是,我谈论的方法- (NSUInteger)supportedInterfaceOrientations和- (BOOL) shouldAutorotate- 如果你也实现了这些方法被编译器忽略和合成- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
我有一个旨在运行Landscape的应用程序.这是一个Cocos2D应用程序.它工作正常,直到我添加另一个窗口(如显示广告)或我显示模态视图控制器.
当我这样做时,即使我有明确的设置,窗口/视图仍然会旋转 shouldAutoRotate = NO
此外,Apple表示如果shouldAutorotate返回NO ,则不会调用supportedInterfaceOrientations.但是,在调用shouldAutorotate之前和之后都会调用它.为什么会发生这种情况?在iOS 8中管理自动轮换的解决方案是什么?
虽然我已经看到许多SO问题解决了以前的iOS版本中的自动旋转问题(在iOS 6中没有调用 shouldAutorotateToInterfaceOrientation中的如何设置管理自动旋转的最详尽描述),似乎没有解决被调用的supportedInterfaceOrientations的问题即使shouldAutoRotate = NO; 并且视图仍在旋转,即使它被告知不要旋转.
为了完全解释我的解释,这里是我如何设置它的描述:
首先,为了显示启动图像,我被迫在info.plist中设置设备方向以支持所有方向.否则,启动时屏幕为黑色.
接下来,我的代码是如何实现的:
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
...
// Init the 2nd window
secondWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // secondWindow is defined as a UIWindow
// Init the second View Controller
nrViewController = [[NonRotatingViewController alloc] initWithNibName:nil bundle:nil]; // nrViewController is defined as a UIViewController
nrViewController.wantsFullScreenLayout = YES; // this insures that if the status bar it transparent, the view …Run Code Online (Sandbox Code Playgroud) 我需要我的应用程序兼容iPad和iPhone.它有一个tabbarController作为rootViewController.
在iPad中我需要它在Landscape和Portrait上都可用.在iPhone中虽然我需要rootView是Portrait本身,但我确实有一些viewsControllers,它们在tabbarController上呈现,需要在横向和Portrait中可用(例如用于播放Youtube视频的viewController).所以我按如下方式锁定tabbarController的旋转(在UITabbarController子类中).
# pragma mark - UIRotation Methods
- (BOOL)shouldAutorotate{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
}
- (NSUInteger)supportedInterfaceOrientations{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
我打算做的是通过锁定rootviewController(tabbarController)的旋转,我锁定tabbarController中的所有VC(仅在iPhone上),并且tabbarController顶部显示的视图可以根据设备方向旋转.
问题
一切都按预期工作,直到应用程序在iPhone中的风景中启动.在横向模式下启动时,应用程序默认为横向并以横向模式启动应用程序,这不是预期的.即使设备方向为横向,它也应在纵向模式下启动.由于我关闭iPhone的自动旋转,应用程序继续在横向本身导致错误.我尝试使用此方法强制应用程序在应用程序中以纵向方式启动:didFinishLaunchingWithOptions:
#pragma mark - Rotation Lock (iPhone)
- (void)configurePortraitOnlyIfDeviceIsiPhone{
if ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone))
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
}
Run Code Online (Sandbox Code Playgroud)
问题仍然存在.我已经允许在info.plist上为iPad和iPhone提供SupportInterfaceOrientaions键的所有方向选项,因为我需要应用程序才能在iPhone中使用,即使只有几个viewControllers.如果我可以以某种方式强制该应用程序以纵向方向启动,即使设备方向是横向,也可以解决该问题.如果错误,请纠正我,如果没有,任何帮助使应用程序以纵向模式启动将不胜感激.
谢谢
objective-c rotation uitabbarcontroller ios landscape-portrait
我不希望我的应用程序被美化,并始终是porttrait.So我使我的应用程序部署信息只设置肖像.但是当我需要在我的应用程序中显示任何图像或视频时,我需要横向模式以便更好地显示.
我可以通过检测设备方向的变化
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
- (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
case UIDeviceOrientationPortrait:
/* */
break;
case UIDeviceOrientationPortraitUpsideDown:
/* */
break;
case UIDeviceOrientationLandscapeLeft:
/* */
break;
case UIDeviceOrientationLandscapeRight:
/* */
break;
default:
break;
};
}
Run Code Online (Sandbox Code Playgroud)
但是,即使应用程序部署信息纵向被锁定,如何手动更改设备方向?
这不起作用
NSNumber *value=[NSNumber numberWithInt: UIDeviceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
Run Code Online (Sandbox Code Playgroud) ios ×5
ios6 ×4
iphone ×4
objective-c ×3
rotation ×3
orientation ×2
autorotate ×1
cocoa-touch ×1
ios8 ×1
portrait ×1
uikit ×1
xcode ×1