Lar*_*s - 5 xcode landscape-portrait ios6
将我的应用程序更新为iOS6标准时,纵向/横向消失了.当我使用Xcode 3构建时,Ir工作得很好.但是现在使用最新的Xcode和最新的SDK,旋转消失了,它始终处于纵向模式.无论我在"支持的界面方向"中加入什么.我以前用来获得旋转的代码似乎根本没有效果.我有这些台词.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
switch (toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
return YES;
default:
return NO;
}
}
Run Code Online (Sandbox Code Playgroud)
我如何更改以及如何更改以使其再次运行?
may*_*uur 17
首先,在AppDelegate中,写下这个.这是非常重要的
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return (UIInterfaceOrientationMaskAll);
}
Run Code Online (Sandbox Code Playgroud)
然后,对于只需要PORTRAIT模式的UIViewControllers,编写这些函数
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait);
}
Run Code Online (Sandbox Code Playgroud)
对于也需要LANDSCAPE的UIViewControllers,将掩码更改为All.
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskAllButUpsideDown);
//OR return (UIInterfaceOrientationMaskAll);
}
Run Code Online (Sandbox Code Playgroud)
现在,如果要在Orientation更改时进行一些更改,请使用此功能.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
}
Run Code Online (Sandbox Code Playgroud)
编辑:
很大程度上取决于你的UIViewController嵌入哪个控制器.
例如,如果它在UINavigationController中,那么您可能需要将UINavigationController子类化为覆盖这样的方向方法.
子类化UINavigationController(层次结构的顶层视图控制器将控制方向.)确实将其设置为self.window.rootViewController.
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
Run Code Online (Sandbox Code Playgroud)
从iOS 6开始,UINavigationController不会要求其UIVIewControllers提供方向支持.因此我们需要将其子类化.
如何在应用程序中支持一个或多个横向控制器,主要是在ios6中的肖像:
1)在AppDelegate中
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
UINavigationController* ns = (UINavigationController*)self.window.rootViewController;
if (ns) {
UIViewController* vc = [ns visibleViewController];
//by this UIViewController that needs landscape is identified
if ([vc respondsToSelector:@selector(needIos6Landscape)])
return [vc supportedInterfaceOrientations];
}
return UIInterfaceOrientationMaskPortrait; //return default value
}
Run Code Online (Sandbox Code Playgroud)
2)在需要横向(或纵向+景观等)的UIView控制器中:
//flag method
-(void)needIos6Landscape {
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
3)在控制器中,您可以从控制器返回,可以在横向上旋转 - 这很重要,否则他们会在从启用风景的VC返回时重新拍摄景观.
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
4)(可能不需要,但肯定..) - 您使用的子类导航控制器,并添加:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
UIViewController* vc = [self visibleViewController];
if (vc) {
if ([vc respondsToSelector:@selector(needIos6Landscape)]) {
return [vc supportedInterfaceOrientations];
}
}
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
重要的一步是从你的应用程序中请求仅定向控制器,因为在控制器之间的转换期间,有一段时间有一些系统控制器作为root,并且将返回不正确的值(这花了我2小时才发现,这是它的原因没工作).
| 归档时间: |
|
| 查看次数: |
13372 次 |
| 最近记录: |