UIImagePickerController叠加层自动旋转

And*_*res 5 iphone camera cocoa-touch objective-c

我正在使用UIImagePicker访问我的iPhone应用程序上的相机。我希望能够为图像选择器提供两个不同的叠加层,具体取决于iPhone的方向。是否有可能做到这一点?看来,如果将以下方法放在拥有UIImagePickerController的类中,则根本不会调用它,而在上面的任何uiviewcontroller中,只有在UIImagePickerController不活动时才调用它。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   NSLog(@"shouldAutorotate called");
   return YES;
}
Run Code Online (Sandbox Code Playgroud)

任何想法如何达到预期的效果?

Nim*_*rod 3

文档说 UIImagePickerController 仅支持纵向模式,因此可能没有支持的方法来执行此操作。

如果您使用 presentModalViewController:animated 来显示图像选择器,那么我相信只有模态控制器才会收到像 shouldAutorotateToInterfaceOrientation 这样的消息。

通常,您可能能够对 UIImagePickerController 进行子类化以覆盖适当的方法,但似乎也不支持子类化。

我怀疑您将必须实际使用 UIAccelerometer 并在覆盖视图上进行手动视图旋转以响应加速消息。

编辑:

实际上,尝试使用 [NSNotificationCenter addObserver: for UIDeviceOrientationDidChangeNotification。