objective-c - 在 iOS 中手动更新界面方向

标签 objective-c ios cocoa-touch orientation

我的 iOS 应用程序支持除 PortraitUpsideDown 之外的所有方向。 但在应用程序中,我有一个带有首选项的 View ,我希望它仅以纵向显示。因此,每当显示此 View 时,都会根据需要旋转它,使其处于纵向模式。这意味着用户也将在纵向模式下旋转设备以设置首选项,然后在关闭此 View 界面后现在应该具有纵向方向。 问题是,在首选项 View 隐藏后,界面保持横向状态,因为我在显示此 View 后阻止自动旋转。 因此,在隐藏 View 后,我想手动将界面更新为当前设备方向。我该怎么做?


self.view.hidden=NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.view.alpha=1.0;
[UIView commitAnimations];

在其 super View 上执行 LongPressGesture 之后,从 OptionsViewController 调用此代码。

最佳答案

我根据 Marek R 提出的解决方案创建了一个 UIViewController 扩展来强制更新 Controller 的方向。自从 iOS 新版本以来,他的解决方案不再起作用。我在这里发布了我的强制方向更新的解决方案(为了考虑 Controller 支持的方向方法),而不会产生副作用。希望对您有所帮助。

UIViewController *vc = [[UIViewController alloc]init];
[[vc view] setBackgroundColor:[UIColor clearColor]];
[vc setModalPresentationStyle:(UIModalPresentationOverFullScreen)];
[self presentViewController:vc animated:NO completion:^{
    dispatch_async(dispatch_get_main_queue(), ^{
        [vc dismissViewControllerAnimated:YES completion:completion];
    });
}];

关于objective-c - 在 iOS 中手动更新界面方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11013843/

相关文章:

iphone - 在单元格中有 UITextView 的情况下无法选择 UITable 单元格

objective-c - 在 objective c 类中使用委托(delegate)调用 swift 方法

ios - IP 配置 apple80211 Open() 在 iOS8 上崩溃

ios - 具有针对同一事件的多个目标操作的 UIButton

iphone - 如何将 UIBarButtonItem 放置在 UIToolbar 的右侧?

objective-c - '-[__ NSCFArray objectAtIndex:]:索引(1)超出范围(0)'崩溃

ios - GoogleService-info.plist 中的 Build Settings User-Defined Setting

ios - Swift 中的下划线按钮文本

objective-c - 如何在部署目标 < 4.0 的项目中仅引用 iOS 4.0 枚举?

objective-c - 从 NSString 中删除开始和尾随的新行字符