我的 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/