2012-10-01 47 views
0

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

现在,我这样做...

- (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时,它假定我必须是肖像(即使当我手动旋转以至于我不是)时,并显示不正确。

回答

1

尝试使用[[UIApplication sharedApplication] setStatusBarOrientation:(UIInterfaceOrientation)];当你manualy旋转视图

+0

哇真棒,谢谢一堆!有趣的故事......我最近做了大量的代码重组/清理工作,并且想到了它(并且通过我的git历史证实了这一点),我曾经在我的代码中拥有这行代码,但因为我不记得原因它在那里!我不会再忘记这段代码的目的,哈哈。 – MikeS

+0

(尤其是因为这次有详细的评论) – MikeS

0

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

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

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

谢谢,但问题不是我的轮换不工作。这就是说,我的UIView没有意识到它甚至没有被旋转(因为我返回“interfaceOrientation == UIDeviceOrientationPortrait”),所以UIActionSheets和MailComposer自动显示在父视图的方向上,总是以纵向显示,即使我手动旋转我的视图,以免它看起来像是在肖像。 – MikeS

0

安东ķ报告的线

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

作品我没问题!当我想使用CGAFFineTransformMakeRotation方法手动旋转UIViewController的UIView以旋转视图PI/2弧度时,IT是否仅仅是休息我的元素。

这条线,设置状态栏的方向你想要的(UIInterfaceOrientation),用于制造UIView的完美呈现“手动”旋转到(UIInterfaceOrientation)我想要的。

结果,这条线也使得UIMessageView的进一步介绍,它出现在(UIInterfaceOrientation)你指示。