Tit*_*eul 5 objective-c uiviewcontroller ios
我的应用程序支持纵向和横向方向.我使用以下代码从位于UITabBarController中的UIViewController以模态方式呈现UIViewController:
self.modalViewController = [[ModalViewController alloc] init];
[self presentViewController:self.modalViewController animated:YES completion:^{
}];
Run Code Online (Sandbox Code Playgroud)
ModalViewController是一个控制器,只能由Landscape中的用户看到.它应该能够从LandscapeRight旋转到LandscapeLeft.这是它的样子:
@implementation ModalViewController
#pragma mark - UIViewController - Orientation
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate
{
return YES;
}
#pragma mark - NSObject
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
}
#pragma mark - UIViewController - Status Bar
- (BOOL)prefersStatusBarHidden
{
return YES;
}
@end
Run Code Online (Sandbox Code Playgroud)
控制器从左侧向上滑动,并在95%的时间内完全覆盖屏幕.但有5%的时间,它从底部向上滑动,仅覆盖屏幕的上半部分.
以下是它工作正常时的样子:
这是它在不能正常工作时的样子:
我创建了一个示例项目,可以在这里找到:https://github.com/TitouanVanBelle/Bug
有一个UI测试目标,以帮助重现该问题,但它很少有效.
有谁知道为什么会这样?
您的应用程序支持纵向、横向左和横向右方向。
在 ModalViewController.m 中更新以下方法 -
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape|UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
您的 ModelViewController 仅支持横向,因此出现此问题。
您也可以使用UIInterfaceOrientationMaskAllButUpsideDown代替UIInterfaceOrientationMaskLandscape|UIInterfaceOrientationMaskPortrait 。
编辑1
根据您的要求,您可以通过更新 ModalViewController.m 中的以下代码来强制旋转当前方向。
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
622 次 |
| 最近记录: |