我有一个包含UICollectionView的UIViewController。在点击任何UICollectionViewCell时,我会提供一个模态视图控制器。
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;
}
将弹出视图锁定到当前方向还需要什么(或代替)?
答案 0 :(得分:1)
尝试添加它,(iOS> 6)
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
要支持iOS 5或更低版本,您必须额外添加:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}