标签: uiinterfaceorientation

如何在Android Instrumentation测试中强制更改方向?

我正在使用ActivityInstrumentationTestCase2类为应用程序编写一些验收测试.我想在测试中引起方向更改,以确保发生许多事情.其中包括确保保留Activity状态,同时我还要确保使用适当的方向布局.

我知道我可以简单地测试onSaveInstanceState/onRestoreInstanceState/onPause/onResume/etc. 确保保留实例状态的方法.但是,我想知道是否存在导致方向改变事件的机制?

这是否会涉及注入某种运动事件来诱骗设备/仿真器认为它已被旋转,或者是否存在由仪器提供的实际方法?

谢谢和干杯!

testing instrumentation android screen-orientation uiinterfaceorientation

24
推荐指数
2
解决办法
2万
查看次数

为什么在iOS 8中我的应用程序在启动时采取错误的方向

我的iOS 7应用程序正常工作.今天我用Xcode 6尝试了它,当我运行它时,我有一个令人讨厌的惊喜:(:

在此输入图像描述 您可以看到Xcode现在绘制我的viewController,就像它处于纵向模式一样,但正如您所看到的那样是横向模式.

你知道iOS 8中有什么变化吗?:/我使用了以下定位方法:

  • (NSUInteger)supportedInterfaceOrientations
  • (BOOL)shouldAutorotate
  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

编辑:

我发现这个方法:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{
 return UIInterfaceOrientationMaskLandscape;
}
Run Code Online (Sandbox Code Playgroud)

现在我的第一个viewcontrollers正常工作:).问题是当我显示一个模态(改变UIInterfaceOrientationMaskAll中的方法集)时重新制作截图的丑陋效果.我正是在这种模式下改变我的方法:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if(self.restrictRotation)
    {
        return UIInterfaceOrientationMaskLandscape;
    }    
    else
    {
        return UIInterfaceOrientationMaskAll;
    }
}


// THIS IS A DELEGATE OF MODAL VIEW CONTROLLER
- (void)updateInterfaceAfterDocumentPreviewViewController
{
    NSLog(@"updateInterfaceAfterDocumentPreviewViewController");

    [[UIApplication sharedApplication]     setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];

    AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
    appDelegate.restrictRotation = YES;
}
Run Code Online (Sandbox Code Playgroud)

cocoa-touch ipad uiinterfaceorientation ios

24
推荐指数
3
解决办法
1万
查看次数

iPad横向和纵向尺寸等级的不同布局

如何使用Size类设计具有不同布局的iPad横向和纵向屏幕.我只能找到两个方向的w-regular和h-regular.示例:我需要使用Size Class在纵向和横向上垂直对齐2个视图

iphone ipad uiinterfaceorientation ios size-classes

24
推荐指数
3
解决办法
1万
查看次数

了解iOS 6界面方向更改

补充: 我看到我的问题经常在没有赞成的情况下被查看,所以我决定你们没有得到你搜索的内容.重定向到有关如何处理iOS6中的方向更改的答案非常好的问题

方向变化的具体要求: 限制轮换

欢迎Upvotes :)


我已经从Master Detail模板创建了一个新项目,并尝试以横向方向启动它.如你所知

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

方法已弃用,我们必须使用

- (NSUInteger)supportedInterfaceOrientations

和/或

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

这是我的代码:

- (NSUInteger)supportedInterfaceOrientations {
    NSLog(@"supported called");
    return UIInterfaceOrientationMaskAll;//Which is actually a default value
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    NSLog(@" preferred called");//This method is never called. WHY?
    return UIInterfaceOrientationLandscapeRight;
}
Run Code Online (Sandbox Code Playgroud)

正如你所看到的那样,我试图在首选方法中返回横向,但它永远不会被调用.ps文档说明:

讨论系统在全屏显示视图控制器时调用此方法.当视图控制器支持两个或更多方向时,您可以实现此方法,但内容在其中一个方向中最佳.

如果视图控制器实现此方法,则在显示时,其视图将以首选方向显示(尽管稍后可以将其旋转到另一个受支持的旋转).如果未实现此方法,系统将使用状态栏的当前方向显示视图控制器.

所以,问题是:为什么永远不会调用prefferredOrientation方法?我们应该如何在不同的控制器中处理不同的方向?谢谢!PS不会将问题标记为重复.我调查了所有类似的问题,他们没有我的答案.

iphone objective-c uiinterfaceorientation ios6

23
推荐指数
2
解决办法
2万
查看次数

强制视图控制器方向在 iOS 16 beta 中工作吗

根据 iOS 和 iPadOS 16 Beta 3 发行说明:- 尝试在 \xc2\xa0 UIDevice \xc2\xa0via\xc2\xa0上设置方向setValue:forKey:\xc2\x80\x99 不受支持且不再有效。相反,他们说使用:preferredInterfaceOrientationForPresentation。

\n

preferredInterfaceOrientationForPresentation就我而言,通过使用或 ,强制视图控制器方向在 iOS 16 beta 中不起作用requestGeometryUpdate

\n

以前,UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue,\xc2\xa0forKey: "orientation")工作正常。

\n

iphone uiinterfaceorientation ios swift ios16

23
推荐指数
3
解决办法
2万
查看次数

禁用UIView的自动旋转

我的应用程序由后台UIView中的工具栏和AVCaptureVideoPreviewLayer组成.我想看看关于设备方向的工具栏旋转,所以在我的主ViewController中,我实现了这个功能:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait
            || interfaceOrientation == UIInterfaceOrientationLandscapeLeft
            || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)

这很好用,但是当界面方向改变时,我看到背景UIView(带有视频层)也在旋转,所以我的视频视图现在向左或向右旋转90度......这真的很酷!
所以我的问题是:有没有办法在特定的UIView上禁用自动旋转动画?

我已经看到了一个类似的问题:为单个UIView禁用自动旋转,但答案不适合我的问题,我真的需要背景视图不要移动,不要用一种"计数器来解决问题动画".所以我决定提出这个话题.

有任何想法吗 ?

谢谢 !

iphone uiview uiinterfaceorientation

21
推荐指数
2
解决办法
1万
查看次数

确定屏幕的方向而不是设备的方向

[[UIDevice currentDevice] orientation]方法返回超出纵向和横向方向的多个方向.我很清楚检查返回的方向是否"有效",不幸的是,当我的应用程序需要特定的方向来确定运行哪些方法时返回的方向不是"有效",我无法知道哪种方法是适当.

我已经尝试了很多解决方案,但是现在我唯一能够解决的问题是检查方向是否正确LandscapeLeft或者LandscapeRight如果不是我认为屏幕是纵向的.不幸的是,当设备面朝上并且屏幕处于横向时,情况并非如此.

我试图使用父视图控制器的方向:

parentController.interfaceOrientation;
Run Code Online (Sandbox Code Playgroud)

不幸的是它返回UIDeviceOrientationUnknown.我搜索SO和谷歌搜索遇到此问题的其他人.看来愚蠢,我认为苹果将有什么,但LandscapeLeft/RightPortraitUp/Down他们的方位.

我真正需要的是APPS方向而不是设备,因为这些有时是不一致的.有什么建议?

screen-orientation uiinterfaceorientation ios

20
推荐指数
1
解决办法
2万
查看次数

游戏中心仅在i OS 6中登录

加载游戏中心时,其默认方向为纵向.为了将其锁定在横向模式中,添加了一个类别.

@implementation GKMatchmakerViewController (LandscapeOnly)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return ( interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate {
    return NO;
}
@end
Run Code Online (Sandbox Code Playgroud)

它在iOS 6下面工作正常.但在iOS6中显示错误.

由于未捕获的异常'UIApplicationInvalidInterfaceOrientation'而终止应用程序,原因:'支持的方向与应用程序没有共同的方向,并且shouldAutorotate返回YES'

请解释一下解决方案.

iphone uiinterfaceorientation game-center ios6

20
推荐指数
1
解决办法
6648
查看次数

无法在iOS 6中处理方向?

我在用

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

委托根据方向类型更改视图的框架

if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
    self.view.frame=CGRectMake(0,0,500,300);
}
else
{
    self.view.frame=CGRectMake(0,0,300,400);
}
Run Code Online (Sandbox Code Playgroud)

如何在iOS 6中处理相同的情况

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
Run Code Online (Sandbox Code Playgroud)

已在iOS6中弃用.

我正在使用以下委托来设置所有方向.

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationAllMask;
}
Run Code Online (Sandbox Code Playgroud)

但,

-(BOOL)shouldAutoRotate
{
    return YES;

}
Run Code Online (Sandbox Code Playgroud)

没有被调用.如何处理这种情况?

在此输入图像描述

ipad uiinterfaceorientation autoresizingmask ios6 iphone-5

20
推荐指数
1
解决办法
1万
查看次数

在iOS6中的单个UIViewController上禁用自动旋转

我有一个项目使用UINavigationControllersegues工作正常,所有这些都正确旋转,事情是......我只是想禁用autorotation特定的UIViewController.我试过这个:

- (BOOL)shouldAutorotateToInterfaceOrientation:
                               (UIInterfaceOrientation)interfaceOrientation {    
    return NO;
}

// New Autorotation support for iOS 6.
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0){
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用,我UIViewController会自动旋转,欢迎任何帮助:)

xcode objective-c uiinterfaceorientation autorotate ios6

19
推荐指数
3
解决办法
3万
查看次数