【发布时间】:2013-07-23 23:52:15
【问题描述】:
我正在使用
在我的父视图控制器上显示子视图控制器childView1 *viewController = [[childView1 alloc]initWithNibName:examTFVC_NIB bundle:nil row:gesture.view.tag productID:test_productID size:testsize Duration:duration];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
self.view.alpha = 0.4f;
viewController.view.backgroundColor = [UIColor clearColor];
viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:viewController animated:YES completion:NULL];
我只在我的父视图控制器及其横向上显示透明视图控制器。 但问题是,当我将设备从横向左到右或从右到左更改时,我的子视图控制器方向发生了变化,但父视图控制器保持相同的方向。
当我不显示子视图控制器时,我的父视图控制器方向发生了变化,如何更改父视图控制器的方向以及子视图控制器?
我试图通过编程将通知中心从孩子传递给父母来改变方向来改变方向。
在子视图控制器中
- (NSUInteger)supportedInterfaceOrientations
{
NSUInteger supportedOrientations = UIInterfaceOrientationMaskLandscape;
[[NSNotificationCenter defaultCenter] postNotificationName:@"RotateParent"object:nil];
return supportedOrientations;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight );
}
- (BOOL)shouldAutorotate
{
return YES;
}
在父视图控制器中
-(void)rotateParent:(NSNotification *)notification
{
CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI);
self.view.transform = transform;
NSLog(@"Parent rotate ");
}
但是当我单击以在父视图上显示我的孩子时,我的“rotateParent”方法默认执行一次。 任何其他解决方案?
【问题讨论】:
-
所以您无法在后续轮换中传递通知,对吧?
-
你可以尝试从 shouldAutorotateToInterfaceOrientation 发送通知
-
@prasad 这不起作用..因为它只支持到 ios 5 ..我正在测试 ios 6
-
仅供参考——您使用的术语不正确。呈现控制器并不会使该控制器成为孩子。当您使用 addChildViewController: 或在情节提要中使用容器视图时,您将获得父子关系。为您的场景提供了正确的术语并展示了视图控制器。
标签: iphone ios ipad ios5 uiinterfaceorientation