旋转和包含api
问题描述:
我有两个视图控制器,A和B.A意味着只支持肖像,而不是B可以支持风景。我使用包含API显示B.旋转和包含api
[self addChildViewController:child];
[self.view addSubview:child.view];
child.view.frame = self.view.bounds;
[child didMoveToParentViewController:self];
我实现
- (BOOL)shouldAutorotate
{
UIViewController *current = _presentingChild ? _child : self;
return [current shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
UIViewController *current = _presentingChild ? _child : self;
return [current supportedInterfaceOrientations];
}
一切就像一个魅力。如果设备呈现A状态并呈现B状态,则立即旋转。
问题出现在我解雇B.如果设备是风景A显示风景(并且这不应该发生)。
你有什么建议如何面对这个问题?我知道我可以使用模态控制器,这将解决问题。但我不想在这种特定情况下使用模态vc。
答
如果我理解正确,shouldAutorotate
和supportedInterfaceOrientations
方法位于包含B viewcontroller的A viewcontroller中。
如果我是对的,你实现这两个方法的方式是不好的:当当前视图控制器是self的时候(如果_presentingChild条件为false),你应该有一个无限递归,因为,例如,shouldAutorotate将被调用递归没有结束(你正在返回[self shouldAutorotate]
)。
所以,如果你没有遇到无限递归,只有两种可能:
- 这两种方法都不会被调用
- 的_presentingChild条件总是真
检查,让我知道