标签: uiinterfaceorientation

[UIScreen mainScreen] .bounds.size在iOS8中是否依赖于方向?

我在iOS 7和iOS 8中运行了以下代码:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
BOOL landscape = (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight);
NSLog(@"Currently landscape: %@, width: %.2f, height: %.2f", 
      (landscape ? @"Yes" : @"No"), 
      [[UIScreen mainScreen] bounds].size.width, 
      [[UIScreen mainScreen] bounds].size.height);
Run Code Online (Sandbox Code Playgroud)

以下是iOS 8的结果:

Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 568.00, height: 320.00
Run Code Online (Sandbox Code Playgroud)

与iOS 7中的结果相比:

Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 320.00, height: 568.00
Run Code Online (Sandbox Code Playgroud)

是否有任何文件指定此更改?或者它是iOS 8 API中的临时错误?

orientation uiinterfaceorientation ios uiscreen ios8

184
推荐指数
8
解决办法
8万
查看次数

在iOS 8中处理方向更改的"正确"方法是什么?

有人可以告诉我在iOS 8中使用纵向和横向界面方向的"正确"或"最佳"方法吗?似乎我想要用于此目的的所有功能都在iOS 8中被弃用,而我的研究似乎没有明确,优雅的替代方案.我真的应该看看宽度和高度,以确定我们是在纵向还是横向模式?

例如,在我的视图控制器中,我应该如何实现以下伪代码?

if we are rotating from portrait to landscape then
  do portrait things
else if we are rotating from landscape to portrait then
  do landscape things
Run Code Online (Sandbox Code Playgroud)

orientation uiinterfaceorientation ios landscape-portrait ios8

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

从横向方向从iPhone 6 Plus主屏幕启动纵向导致错误的方向

这个问题的实际标题比我可能适合的长:

启动一个应用程序,其根视图控制器仅支持纵向,但在主屏幕处于横向方向时支持iPhone 6 Plus上的横向方向会导致应用程序窗口处于横向方向但设备为在纵向方向.

简而言之,它看起来像这样:

当它应该看起来像这样:

重现步骤:

  1. iPhone 6 Plus运行iOS 8.0.

  2. 一个应用程序,其plist支持所有但纵向倒置的方向.

  3. 应用程序的根视图控制器是UITabBarController.

  4. 一切,标签栏控制器及其所有后代子视图控制器都UIInterfaceOrientationMaskPortrait从中返回supportedInterfaceOrientations.

  5. 从iOS主屏幕开始.

  6. 旋转至横向(需要iPhone 6 Plus).

  7. 冷启动应用程序.

  8. 结果:界面方向损坏.

除了完全禁用横向之外,我无法想到强制执行纵向定位的任何其他方式,这是我无法做到的:我们的网络浏览器模态视图控制器需要横向.

我甚至尝试了子类化UITabBarController并重写supportedInterfaceOrientations以返回仅限纵向的掩码,但是这(即使使用上述所有其他步骤)也没有解决问题.


这是一个显示错误的示例项目的链接.


iphone uiinterfaceorientation ios ios8

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

iOS:加载时的设备方向

似乎当我的应用加载时,它不知道它的当前方向:

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait) {
    NSLog(@"portrait");// only works after a rotation, not on loading app
}
Run Code Online (Sandbox Code Playgroud)

一旦我旋转设备,我得到一个正确的方向,但当我加载应用程序,而不改变方向,似乎使用[[UIDevice currentDevice] orientation]不知道当前的方向.

我第一次加载应用程序时是否还有另一种检查方法?

iphone uidevice uiinterfaceorientation ios

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

RootViewController动画过渡,初始方向错误

所以我按照这个线程:RootViewController Switch Transition Animation将window.rootViewController从A转移到B到C.代码如下所示:

[UIView transitionWithView:self.window 
                  duration:0.5 
                   options: UIViewAnimationOptionTransitionFlipFromLeft 
                animations:^{
                               self.window.rootViewController = newViewController;
                } 
                completion:nil];
Run Code Online (Sandbox Code Playgroud)

问题是我的应用程序只支持横向,但在rootViewController过渡期间,新的视图控制器以纵向模式显示,而不是快速旋转到横向模式.

我确定:

  1. 我已将UISupportedOrientation设置为横向(主页按钮右侧)
  2. 对于每个viewcontroller,在shouldAutoRotateToOrientation方法中,我只为landscape设置

可能是另一个原因?

iphone ipad uiinterfaceorientation ios

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

如何在iOS 6中以编程方式更改设备方向

iOS 5中,我们可以通过编程方式更改设备方向,如下所示:

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
Run Code Online (Sandbox Code Playgroud)

但是在iOS 6 setOrientation中已弃用,我如何在iOS 6中以编程方式更改设备方向?

objective-c uiinterfaceorientation ios

45
推荐指数
5
解决办法
7万
查看次数

iOS7 iPad仅限应用程序,使用UIImagePickerController

我相信这是一个常见的问题,许多答案不再适用,很多只是部分,如果你在iOS7下,你的iPad应用程序只是Landscape,但你想使用UIImagePickerControllerwith source UIImagePickerControllerSourceTypePhotoLibraryUIImagePickerControllerSourceTypeCamera.

如何设置正确,所以它100%工作?并且您没有获得混合方向并避免错误"支持的方向与应用程序没有共同的方向,并shouldAutorotate返回YES".

cocoa-touch uiimagepickercontroller ipad uiinterfaceorientation ios

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

iPad iOS7 - UIPopoverController中的UIImagePickerController具有错误的预览图像

我在UIPopoverController中使用UIImagePickerController,它与iOS6完美配合.使用iOS 7时,显示捕获图像的"预览"图像会旋转,但如果我拍照,则会正确保存.

这就是我选择的方式:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
                              (NSString *) kUTTypeImage,
                              nil];
imagePicker.allowsEditing = NO;
Run Code Online (Sandbox Code Playgroud)

并将其添加到弹出控制器:

self.imagePickerPopOver = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
    [self.imagePickerPopOver presentPopoverFromRect:CGRectMake(aPosViewA.x, cameraButton_y, 100.0, 30.0) inView:self.detailViewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Run Code Online (Sandbox Code Playgroud)

这些是UIScrollView上按钮位置的计算,以显示正确位置的弹出窗口:

presentPopoverFromRect:CGRectMake(aPosViewA.x, cameraButton_y, 100.0, 30.0)
Run Code Online (Sandbox Code Playgroud)

我不认为问题就在那里,因为我尝试了几种组合.

我还尝试在全屏模式下捕获图像,但应用程序只允许使用横向模式.如果以纵向模式拍摄图像并且取消模态视图,则应用程序也将保持纵向模式.如果模态视图被解除,我找不到阻止UIImagePickerController切换到纵向模式或强制应用程序回到横向模式的方法.

UPDATE

我从这里得到了答案,又向前迈进了一步.

我在创建选择器之后和显示弹出窗口之前转换视图:

switch ([UIApplication sharedApplication].statusBarOrientation) {
        case UIInterfaceOrientationLandscapeLeft:
            self.imagePicker.view.transform = CGAffineTransformMakeRotation(M_PI/2);
            break;
        case UIInterfaceOrientationLandscapeRight:
            self.imagePicker.view.transform = CGAffineTransformMakeRotation(-M_PI/2);
            break;
        default:
            break;
    }
Run Code Online (Sandbox Code Playgroud)

只要我不转动iPad,它就能正常工作.为此,我正在注册方向更改事件:

[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)  name:UIDeviceOrientationDidChangeNotification  object:nil];
Run Code Online (Sandbox Code Playgroud)

并更改选择器视图:

- …
Run Code Online (Sandbox Code Playgroud)

uiimagepickercontroller uipopovercontroller uiinterfaceorientation ios ios7

26
推荐指数
1
解决办法
9834
查看次数

MPMoviePlayerController重定向纵向到横向和回到纵向(iOS 4.1)

从iOS 3.2开始,MPMoviePlayerController类允许在视图层次结构中嵌入电影.现在我面临这个问题:我通过放置一个MPMoviePlayerController实例来创建我的纵向视图.当用户触摸"全屏"按钮时,此视图以全屏模式进入,但视图仍保持纵向.当用户旋转设备时,全屏电影视图不会自动旋转,因为我的应用禁止横向界面方向.因此,为了允许电影播放器​​全屏视图的自动旋转,我改变了我的视图控制器shouldAutorotateToInterfaceOrientation:方法如果 - 并且仅当 - 电影播放器​​处于全屏模式时返回YES.这非常有效:当用户全屏进入然后旋转到横向时,播放器会自动旋转到横向并填充整个屏幕.

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    if(UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
        return(YES);
    }

    if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
        return([movieController isFullscreen]);
    }

return(NO);
}
Run Code Online (Sandbox Code Playgroud)

现在,当我在全景视图中触摸"完成"按钮的同时保持横向状态时,会出现问题.全屏关闭,然后我看到的是我的原始视图自动旋转:但我不希望这种自动旋转.

部分但不可接受的解决方案是侦听"MPMoviePlayerDidExitFullscreenNotification",如果界面旋转为横向,则强制重定向以使用未记录的私有函数:

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait]
Run Code Online (Sandbox Code Playgroud)

这有效但不可接受,因为禁止使用此方法.

我试图强制使用方向,[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]但因为我在Tab栏中这不起作用(UITabBar仍然是横向大小).

谢谢你的帮助

iphone uiinterfaceorientation

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

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

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

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

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

谢谢和干杯!

testing instrumentation android screen-orientation uiinterfaceorientation

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