仅在某些视图中的界面方向
我有一个包含 uitableview 的主视图,当用户点击一行时我正在推送另一个视图。我只想旋转子视图并为此编写了代码。但问题是,一旦我推动视图,它也会启用主视图上的方向。
当我向左旋转主视图时,状态栏也会向左更改。我没有在主视图上应用任何方向。我已经在 MainView 上完成了以下操作,但状态栏的代码仍然没有改变。
-(void) viewDidLoad
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(receivedRotate:) name: UIDeviceOrientationDidChangeNotification object: nil];
}
-(void) receivedRotate: (NSNotification*) notification
{
UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
if(interfaceOrientation != UIDeviceOrientationUnknown)
{
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft)
{
[self shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
}
}
如何在主视图中禁用 interfaceOrientation?
I have a Main View that contatins uitableview, and I am pushing another view when the user taps on a row. I want only the child views to rotate and have written code for that. But the problem is once I push the view, it also enables the orientation on the Main View.
When I rotate the main view to the left, the statusbar also changes to the left. I have not applied any orientation on the Main View. I have done the following on the MainView but code still the status bar doesn't change.
-(void) viewDidLoad
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(receivedRotate:) name: UIDeviceOrientationDidChangeNotification object: nil];
}
-(void) receivedRotate: (NSNotification*) notification
{
UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
if(interfaceOrientation != UIDeviceOrientationUnknown)
{
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft)
{
[self shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
}
}
How can I disable interfaceOrientation in the Main view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的主视图控制器中,覆盖此委托:
现在您的主视图控制器将始终处于横向模式。
并删除上面提到的所有代码。
您不应该调用“shouldAutorotateToInterfaceOrientation:”方法。
in your main view controller, override this delegate:
Now your main view controller will always be in landscape mode.
And remove all your code which you mentioned above.
you should not call the "shouldAutorotateToInterfaceOrientation:" method.