gpt4 book ai didi

cocoa - iOS 7 : Restrict device current orientation when modal view controller is presented

转载 作者:行者123 更新时间:2023-12-03 17:11:46 24 4
gpt4 key购买 nike

我有一个 UIViewController,其中包含一个 UICollectionView。点击任何 UICollectionViewCell 时,我会呈现一个模态视图 Controller 。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PopViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"DetailsView"];
vc.view.backgroundColor = [UIColor clearColor];
vc.transitioningDelegate = self;
vc.modalPresentationStyle = UIModalPresentationCustom;
[self presentViewController:vc animated:YES completion:nil];

PopViewController 显示正确。现在我想在呈现 PopViewController 时限制设备方向。也就是说,如果 PopViewController 以纵向模式显示,那么即使我切换到横向模式(在模拟器中使用向左或向右旋转),它也不应该更改为横向,直到我关闭 PopViewController。

我在 PopViewController 中使用了以下代码:

-(BOOL)shouldAutorotate {
return NO;
}

还需要什么(或相反)才能将弹出 View 锁定到当前方向?

最佳答案

在你的模态 Controller 中也尝试添加这个(iOS > 6)

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

要支持 iOS 5 或更低版本,您必须额外添加:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{

return (toInterfaceOrientation == UIInterfaceOrientationPortrait);

}

关于cocoa - iOS 7 : Restrict device current orientation when modal view controller is presented,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22509804/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com