我遇到的问题是didRotateFromInterfaceOrientation方法没有在我的一个viewcontroller子类中触发.
我有一个带有UISplitViewController的iPad应用程序作为主视图.在细节方面,我使用"隐藏"(无工具栏,导航栏)导航控制器进行延迟视图切换.我想要捕获didRotateFromInterfaceOrientation的ViewController在navcontroller层次结构中是两层深.(这些都不应该有所不同,但我会包含这些信息,以防有一些我不知道的特殊情况)
我有:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
// This doesn't work. :(
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
NSLog(@"Rotate Go!");
}
Run Code Online (Sandbox Code Playgroud)
视图旋转得很好,但didRotateFromInterfaceOrientation永远不会触发.
知道我错过了什么吗?
小智 5
如果您的UIViewController在某个根视图中是子级,则默认情况下IB不会将其作为子控制器添加到根控制器.解决此问题的最简单方法是修改根控制器:
- (void)viewDidLoad
{
[super viewDidLoad];
[self addChildViewController:(UIViewController*) self.yourChildController];
}
Run Code Online (Sandbox Code Playgroud)
这应该可以解决问题.现在您的孩子控制器将同时接收:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
Run Code Online (Sandbox Code Playgroud)
和
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
Run Code Online (Sandbox Code Playgroud)
消息.
好吧,我从来没有弄清楚为什么事件没有触发,但我确实找到了一个解决方法:
在两个UISplitViewController委托方法splitViewController:willHideViewController:withBarButtonItem:forPopoverController:和中splitViewController:willShowViewController:invalidatingBarButtonItem:,我正在检测我的视图是否可见,然后在此处执行我的旋转逻辑。
| 归档时间: |
|
| 查看次数: |
13248 次 |
| 最近记录: |