相关疑难解决方法(0)

是否有记录的方式来设置iPhone方向?

我有一个应用程序,我想在某些视图中支持设备旋转,但其他在横向模式下没有特别有意义,所以当我交换视图时,我想强制旋转设置为纵向.

在UIDevice上有一个未记录的属性设置器可以完成这个技巧,但显然会产生编译器警告,并且可能会随着SDK的未来版本而消失.

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

是否有任何记录的方法来强制定位?

更新:我想我会提供一个例子,因为我没有找到shouldAutorotateToInterfaceOrientation,因为我已经实现了它.

我希望我的应用程序支持View 1中的横向和纵向,但只支持View 2中的纵向.我已经为所有视图实现了shouldAutorotateToInterfaceOrientation但是如果用户在View 1中处于横向模式然后切换到View 2,我想强制执行手机旋转回肖像.

iphone cocoa-touch objective-c

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

使用Swift在一个ViewController中强制使用横向模式

我试图在我的应用程序中强制只有一个视图在横向模式,我打电话

override func shouldAutorotate() -> Bool {
    print("shouldAutorotate")
    return false
}

override func supportedInterfaceOrientations() -> Int {
    print("supportedInterfaceOrientations")
    return Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue)
}

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
    return UIInterfaceOrientation.LandscapeLeft
}
Run Code Online (Sandbox Code Playgroud)

视图以纵向模式启动,并在更改设备方向时保持旋转.
永远不会调用shouldAutorotate.
任何帮助,将不胜感激.

landscape ios swift

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

如何以编程方式确定iPhone界面方向?

UIDevice.orientationinclude UIDeviceOrientationFaceUp和 的可能值UIDeviceOrientationFaceDown.虽然知道设备是扁平的可能是有用的,但这并不能告诉我们它是否是平面显示面向纵向或横向模式的界面.有没有办法在设备返回模糊信息的情况下找到GUI的当前方向?我想我可以跟踪方向变化事件以记住最后的纵向/横向方向或检查主要UIView的边界高度和宽度,但这似乎是kludgey.设备或UIView上有一个我失踪的财产吗?

iphone cocoa-touch

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

如何以编程方式设置设备(UI)方向?

希望屏幕上的所有内容(UI)能够从左到右旋转或反之亦然.

我该怎么做呢?这是私人的吗?

我知道

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

让你说出UI可以有哪些方向,但有没有办法一次只强制一个?

干杯

iphone objective-c orientation ios

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

如何在iOS 6中以编程方式获取设备的当前方向?

我开发了iOS应用程序并在iOS6设备上进行了测试.在测试时,我意识到我的应用程序没有按预期响应方向更改.

这是我的代码:

// Autorotation (iOS >= 6.0)
- (BOOL) shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)

确切地说,我想知道iOS中的方向更改调用了哪些方法.

iphone screen-orientation device-orientation ipad-3 ios6

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

iOS:弹出视图控制器时更改界面方向

我的应用程序中的所有视图控制器仅在纵向工作,除了可以是纵向或横向的视图控制器.

我有一些使用场景如下:

  1. 我将两个方向都适用的控制器推送到UITabBarController
  2. 用户从portait到landscape的方向更改
  3. 用户按"后退按钮"

执行这些操作后,应用程序将保持横向方向,并且不会自动将其更改为纵向.

我使用supportedInterfaceOrientations控制视图控制器方向(我使用的是iOS 6.0).我做错了什么?当用户按下后退按钮时应用程序自动将方向更改为允许时,如何才能获得正确的行为?谢谢你的答案!

objective-c screen-orientation uiinterfaceorientation ios

10
推荐指数
1
解决办法
5986
查看次数

无法以横向模式从相机以适当的格式显示图像

我正在使用Ios6中的iPad应用程序,当我们点击右边的按钮时,我正在执行如下操作:

-(IBAction)camerabuttonAction:(id)sender
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.delegate = self;

   self.popoverController = [[UIPopoverController alloc] initWithContentViewController:picker];
   [self.popoverController presentPopoverFromRect:CGRectMake(50, -250, 500, 300) inView:appDelegate.splitview.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我在Land scape模式时,如果我点击按钮.每次使用后,相机将以纵向模式显示(图像以反向模式显示).但是,如果我摇动iPad,它会在LandScape中显示,即正确的方向.

见下图

当我处于Land scape模式时,如果我点击按钮,相机会显示如下图像:

在此输入图像描述

如果我摇动iPad,那么相机会显示如下图像:

在此输入图像描述

我已经尝试了很多并用Google搜索,但我找不到任何解决方案.这是在节省我的时间,所以如果有人工作,请指导我并发布示例代码.

iphone uiimagepickercontroller ipad ios ios-simulator

10
推荐指数
2
解决办法
2380
查看次数

如何在Swift中以编程方式旋转方向?

我尝试了下一个:

UIDevice.currentDevice().setValue(UIInterfaceOrientation.Portrait.rawValue, forKey: "orientation")
Run Code Online (Sandbox Code Playgroud)

viewWillAppear
Run Code Online (Sandbox Code Playgroud)

但它不起作用.如何在viewWillAppear上旋转屏幕?

UPDATE

我使用下一个代码来锁定方向:

var shouldRotate = true
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
    if shouldRotate == true {
        return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    } else {
        return Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue)
    }
}
Run Code Online (Sandbox Code Playgroud)

Swift 4.0

  private func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
        if shouldRotate == true {
            return Int(UIInterfaceOrientationMask.portrait.rawValue)
        } else {
            return Int(UIInterfaceOrientationMask.landscapeLeft.rawValue)
        }
    }
Run Code Online (Sandbox Code Playgroud)

在我的第一个控制器viewWillAppear我设置:

if let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate {
    appDelegate.shouldRotate = true
}
Run Code Online (Sandbox Code Playgroud)

在我的SECOND控制器中:

if let appDelegate = …
Run Code Online (Sandbox Code Playgroud)

orientation ios swift

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