0

在 iOS 中,手动旋转视图的正确方法是什么?我有很多自定义旋转动画,我根本不希望我的视图自动旋转。

现在,我正在做这个...

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return interfaceOrientation == UIDeviceOrientationPortrait;
}

然后,我正在这样做并根据需要响应方向变化:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];

一切正常,除了...当我尝试展示操作表、MailViewController 等时,它们都以纵向显示:(

我怎样才能让我的视图知道,虽然我不希望它自动旋转,但它实际上是在响应我手动处理的方向通知?

编辑:澄清一下,并不是我的旋转不起作用,而是当我呈现 UIActionSheet 时,它假定我必须是纵向的(即使我已经手动旋转而不是),并且它显示不正确.

4

3 回答 3

1

[[UIApplication sharedApplication] setStatusBarOrientation:(UIInterfaceOrientation)];手动旋转视图时尝试使用

于 2012-10-08T09:38:50.550 回答
0

也许你可以从 shouldAutorotateToInterfaceOrientation 中调用一个方法。例如:

    - (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation != UIDeviceOrientationPortrait)
        [self theActionYouWantToPerform]

    // Return YES for supported orientations
    return interfaceOrientation == UIDeviceOrientationPortrait;
}
于 2012-10-01T20:47:33.913 回答
0

Anton K 报道的线路

[[UIApplication sharedApplication] setStatusBarOrientation:(UIInterfaceOrientation)];

工作我很好!当我想使用 CGAFFineTransformMakeRotation 方法手动旋转 UIViewController 的 UIView 来旋转视图 PI/2 弧度时,它只是让我休息的元素吗?

这一行,将状态栏的 ORIENTATION 设置为您想要的(UIInterfaceOrientation),以便“手动”旋转到我想要的(UIInterfaceOrientation)的 UIView 的完美外观。

因此,这一行也使UIMessageView的进一步呈现,出现在您指定的(UIInterfaceOrientation)中。

于 2014-11-14T12:44:28.763 回答