【发布时间】:2016-04-20 10:33:41
【问题描述】:
我需要在应用运行时更改应用方向。我的过程是,如果我打开开关,应用程序应更改其方向(即)(i)如果应用程序以横向运行,然后如果我打开“打开”开关按钮,则设备方向应自动更改为纵向模式。 . (ii) 如果应用程序在纵向模式下运行,如果我关闭开关,那么设备方向应该会自动变为横向模式......我已经尝试过一些东西,但它对我来说不起作用......任何人都可以提供一些解决方案为此..
- (IBAction)PortraitSwitchPressed:(UISwitch *)sender
{
if (sender.isOn)
{
UIInterfaceOrientationMaskPortrait;
[[UIDevice currentDevice]setOrientation:UIInterfaceOrientationPortrait]; // no visible @interface for 'UIDevice' declares the selector setorientation
[self.PortraitSwitch setOn:YES animated:YES];
}
else
{
UIInterfaceOrientationMaskLandscape;
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationMaskLandscape];
[self.PortraitSwitch setOn:NO animated:YES];
}}
【问题讨论】:
标签: ios objective-c uiinterfaceorientation