Ios 手动旋转视图而不是自动旋转

Ios 手动旋转视图而不是自动旋转,ios,uiview,rotation,Ios,Uiview,Rotation,在iOS中,手动旋转视图的正确方式是什么?我有很多自定义旋转动画,我根本不希望我的视图自动旋转 现在,我正在做这个 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return interfaceOrientation == UIDeviceOrientatio

在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时,它假设我必须处于纵向(即使我已经手动旋转,所以我没有),并且显示不正确。

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

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

    // Return YES for supported orientations
    return interfaceOrientation == UIDeviceOrientationPortrait;
}

手动旋转视图时,请尝试使用
[[UIApplication sharedApplication]SetStatusBaroOrientation:(UIInterfaceOrientation)];
手动旋转Anton K报告的行

[[UIApplication sharedApplication] setStatusBarOrientation:(UIInterfaceOrientation)];
很好!当我想使用CGAFFineTransformMakeRotation方法手动旋转UIViewController的UIView时,它就是让我休息的元素吗?旋转视图PI/2弧度

这一行,将状态栏的方向设置为所需的(UIInterfaceOrientation),以使UIView“手动”旋转到所需的(UIInterfaceOrientation)的完美外观


因此,这一行还进一步显示了UIMessageView,它出现在您指出的(UIInterfaceOrientation)中。

谢谢,但问题不是我的旋转不起作用。而是我的UIView没有意识到它甚至被旋转了(因为我回来了)“interfaceOrientation==UIDeviceOrientationPortrait”),因此UIActionSheets和MailComposer(自动以父视图的方向显示)始终以纵向显示,即使我手动旋转视图使其看起来不像纵向。哇,太棒了,谢谢!有趣的故事…我最近做了大量的代码重组/清理,现在回想起来(我的git历史也证实了这一点),我曾经在我的代码中有这一行,但我删除了它,因为我不记得它为什么会出现在那里!我不会再忘记那一行代码的目的哈哈。(特别是因为这次它附带了详细的注释)