gpt4 book ai didi

ios - 强制 UIActionSheet 使用特定方向

转载 作者:可可西里 更新时间:2023-11-01 04:32:02 25 4
gpt4 key购买 nike

我的应用有一个无法改变方向的 View Controller 。将其视为需要固定在原地的运动场。

我现在想放置一个 UIActionSheet,但考虑到用户握持设备的方式,我想将表单与方向相匹配。

UIActionSheet 似乎不像 MFComposerViewController,它不是从 StatusBar 获取方向,我根据方向旋转它,而是从底层 View Controller 获取方向。换句话说,无论设备的握持方式如何,UIActionSheet 都会以纵向显示。

我试过:

CGAffineTransform   t = CGAffineTransformMakeRotation(lastUIAngle);
[actionSheet setTransform:t];
if (UIInterfaceOrientationIsLandscape(lastOrientation))
actionSheet.frame = CGRectMake(0, 0, 480, 320);
else
actionSheet.frame = CGRectMake(0, 0, 320, 480);
actionSheet.center = self.view.center;

我设法获得了正确的方向,但是生成的操作表从纵向出现,并且大小就像它仍然是纵向一样。 action sheet的frame是根据按钮的数量等计算出来的。

有没有人设法强制 UIActionSheet 以指定的方向正确显示?

(我还尝试创建一个新 View ,它经过转换并具有正确的大小,但 UIActionSheet 忽略了它。剩下的就是创建一个自动旋转的新 UIViewController,并让 UIActionSheet 成为它的子项。但是,这意味着我的运动场被新的 View Controller 完全遮盖了。)

最佳答案

原来答案很简单。添加此代码以强制 UIActionSheets 到您想要的任何方向:

tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
tempView.transform = CGAffineTransformMakeRotation(lastUIAngle);
tempView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view.window addSubview:tempView];

UIActionSheet *actionSheet = ...

[actionSheet showInView:tempView];

lastUIAngle 是 pi/2 的倍数,在本例中,我从上次更改方向时保存了它。

关于ios - 强制 UIActionSheet 使用特定方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8100323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com