我想要创建一个UIVIew,当我调用shouldAutorotateToInterfaceOrientation时,它将不会旋转,其他子视图将会旋转。call shouldAutorotateToInterfaceOrientation但锁定旋转的视图
我想保留shouldAutorotateToInterfaceOrientation支持,而不是使用通知。
感谢
我想要创建一个UIVIew,当我调用shouldAutorotateToInterfaceOrientation时,它将不会旋转,其他子视图将会旋转。call shouldAutorotateToInterfaceOrientation但锁定旋转的视图
我想保留shouldAutorotateToInterfaceOrientation支持,而不是使用通知。
感谢
一定要准确地定义你由具有视图时设备旋转“不转”的意思。旋转可能意味着几件事情,具体取决于您引用的坐标系。想一想更好的方法就是,您希望您的视图适合每个设备方向。
只是提醒,shouldAutorotateTo ...是由系统发送到您的视图控制器。你不要自己调用它。它不会导致旋转。它让系统询问您的视图控制器支持哪些方向。
你的VC应该为它支持的所有方向回答YES。受支持的方向是视图为响应设备方向更改而更改布局的方向,因此如果对给定方向发生任何布局更改,则对shouldAutorotateTo的回答可能为YES。
更改给定接口方向的子视图布局主要是您的责任。视图有一个autoresizingMask,它是一个向量,用于描述相对于父级的大小和位置的一些选项,这通常是足够的。完全控制方向变化布局的方法是通过实现willAnimateRotationToInterfaceOrientation。
例如,这里是一个相当宽松的shouldAutorotate,使所有,但一个方向......
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
而且这里是你将如何控制如何子视图上旋转布局...
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
UIView *testView = [self.view viewWithTag:16];
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
// change frames here to make the ui appear according to your spec
// including however you define "not rotating" for each view
self.subviewA.frame = .....
self.subviewB.frame = .....
} else {
self.subviewA.frame = .....
self.subviewB.frame = .....
}
}
如果你想让一个UIView不能随着方向旋转,简单的解决方案之一就是像这样将视图添加到应用程序的顶部窗口。因为窗口不随设备方向旋转。
[[[[UIApplication sharedApplication]windows]objectAtIndex:0]addSubview:customView];
你能告诉我一些代码如何防止uiview旋转?你的意思是平分抽签方法吗? – Janub 2012-07-08 15:24:32