是否可以横向旋转UIAlertController(和Alert)? [英] Is it possible to rotate UIAlertController (and Alert) in landscape orientation?

查看:746
本文介绍了是否可以横向旋转UIAlertController(和Alert)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编辑一个应用程序,我添加了一个新的UIViewController以在一个布局中配置多人游戏。

I am editing an app where I added a new UIViewController to configure a multiplayer game in one layout.

我为每个玩家添加了两个按钮(顶部按钮,机器人按钮)。每个按钮在屏幕上生成一个警报(记住它是横向的),但问题是,玩家2看不到警报旋转,我的意思是,警报应该以他的方向显示在我面前。

I have added two buttons for each player (top button, bot button). Each button generates an alert at the screen (remember it is in landscape orientation ) but the problem is, player 2 do not see the alert rotated, I mean, the alert is supposed to be shown in his orientation, in front of me.

有没有办法做到这一点?我想为播放器2轮换一个警报,看不到警报的信息。

As there any way to do this? I want to rotate an Alert for the player 2 will not see the information of the alert turned.

这里有警报代码:

@IBAction func ShowAlert(){
let message = "Test"
let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)

let action = UIAlertAction(title: "OK", style: .Default, handler: nil)

    alert.addAction(action)

    presentViewController(alert, animated: true, completion: nil)
}


推荐答案

这是一种旋转警报控制器视图的方法,尽管它并不完美。控制器试图根据方向呈现,我发现在呈现之前尝试对其进行转换是不成功的。

Here is a way to rotate an alert controller view, although it is not perfect. The controller tries to present based on the orientation and I found that attempting to transform it before it is presented is unsuccessful.

为了最初看不到不正确的方向,您必须将警报设置为隐藏,然后在显示后将其设为可见。

In order to not see "incorrect" orientation initially, you must set the alert to hidden and then make it visible once it is "presented".

let alert // setup

alert.view.hidden = true;
[self presentViewController:c animated:YES completion:^{
    alert.view.transform = CGAffineTransformMakeRotation(M_PI);
    alert.view.hidden = false;
}];

我遇到的唯一未解决的问题是,在用户与警报交互后,它会闪回初始转换(取决于取向)。我目前还没有找到解决方案,但如果我这样做会更新。

The only outstanding issue I have with this is that after the user interacts with the alert, it flashes back to the initial transformation (orientation dependent). I currently have not found a solution for this, but will update if I ever do.

或者,使用自定义警告将解决此问题,因为您可以更好地控制其视图。这可能是更可靠的方法。

Alternatively, using a custom "alert" would solve this problem as you would have more control over its view. This is probably the more reliable approach.

这篇关于是否可以横向旋转UIAlertController(和Alert)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆