开发者

UIImagePickerController overlay autorotate

开发者 https://www.devze.com 2022-12-15 04:42 出处:网络
I am using the UIImagePicker to access the camera on my iPhone app. I would like to be able to have two different overlays 开发者_Python百科for the imagepicker, depending on the orientation of the iPh

I am using the UIImagePicker to access the camera on my iPhone app. I would like to be able to have two different overlays 开发者_Python百科for the imagepicker, depending on the orientation of the iPhone. Is it possible to do this? It seems like if I place the following method in the class that owns the UIImagePickerController, it does not get called at all, and in any uiviewcontroller above that it only gets called once the UIImagePickerController is not active.

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   NSLog(@"shouldAutorotate called");
   return YES;
}

Any idea how to achieve the desired effect?


The documentation says that the UIImagePickerController only supports portrait mode so it could be that there's no supported way of doing this.

If you're using presentModalViewController:animated to display the imagepicker then I believe only the modal controller will get messages like shouldAutorotateToInterfaceOrientation.

Normally you might be able to subclass UIImagePickerController to override the appropriate methods, but it seems that subclassing isn't supported either.

I suspect that you're going to have to actually use UIAccelerometer and do manual view rotation on your overlay view in response to acceleration messages.

Edit:

Actually, try using [NSNotificationCenter addObserver: for UIDeviceOrientationDidChangeNotification.


Actually using the raw accelerometer data, you can determine when to swap out the overlay, so that did it!


You can rotate the overlay view using transform property of overlay like this

cameraOverlayView.transform = CGAffineTransformMakeRotation(-3.141592/2);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号