ios - 将一个 View 方向更改为横向

标签 ios objective-c device-orientation

我正在开发一个用户将观看直播 channel 的项目。但是我在这里遇到了一个小问题,我已经非常努力地尝试但没有找到任何解决方案。我的应用程序将支持除最后一个 View 之外的所有 View 的纵向方向。最后一个 View 将仅支持横向。是否可以? 我搜索并尝试了以下代码

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];

//

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

//

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation        {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);}

最佳答案

关注this link .希望你能在这里得到答案。

该链接显示了如何将所有 View 保持为纵向模式,但一个 View 将处于横向模式。

您需要执行以下操作:

第一:

在所有为肖像修复的 Controller 中实现这一点:

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

并为景观 Controller 实现这个:

- (BOOL)shouldAutorotate
{
    return YES;
}


- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

第二:

 // Fetch the status bar from the app and set its orientation as required. 
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];

// Create an empty view controller, present it modally and remove it directly afterwards
UIViewController *mVC = [[UIViewController alloc] init];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];
// Now the device is rotated to the desired orientation. Go from there.

希望有用。

关于ios - 将一个 View 方向更改为横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23992792/

相关文章:

iphone - iOS 基本 FTP 设置;读写流

ios - 在 iOS 7 中更改 UITableViewCellStyleValue2 textLabel 的整体 tintColor 和字体大小

ios - Cocoapods ld : library not found for -lPods-Projectname

iPhone ABPeoplePickerNavigationController - 如何从地址簿中选择一个人的两个不同多值属性的两个单个条目

html - 如何防止在 mobile-safari 中改变方向后获得额外的宽度

javascript - deviceorientation 事件在 Firefox 桌面上不起作用

ios - 从 IOS 上传图像文件到 Web 服务器

ios - SearchBar 文本仅工作 viewDidLoad

iphone - 在应用程序不运行期间,如何增加applicationIconBadgeNumber的值?

Android:获取当前设备方向