views:

421

answers:

2

Hi !

My application is composed of a toolbar and an AVCaptureVideoPreviewLayer in a background UIView. I'd like to see that toolbar rotate regarding the device orientation, so in my main ViewController, I implemented the function :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait
            || interfaceOrientation == UIInterfaceOrientationLandscapeLeft
            || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

This works fine, but when the interface orientation is changed, I see that the background UIView (with a video layer) is also rotating, so my video view is now playing 90 degrees left or right... Which is not really cool !
So my question is : is there any way to disable the auto-rotation animation on a specific UIView ?

I have seen one similar question to this one : Disabling autorotate for a single UIView, but the answers doesn't fit my problem, I really need the background view to do not move, not to get around the problem with a kind of "counter animation". So I decided to bring up this topic.

Any ideas ?

Thanks !

A: 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  return NO;
}

Or were you saying to disable it only when a certain view is showing? If so, you can check for this using UIView's isDescendantOfView method.

William Jockusch
Well, I don't want to disable the whole interface rotation, just to disable it on a specific UIView in the view hierarchy of the main viewController. It means when I rotate the device, I see the toolbar rotating, but not the video view.
super_tomtom
+1  A: 

Try this:

myVideoCaptureLayer.orientationSupported = NO;
christo16
As I understood, the orientationSupported property is readonly and tells if the device is able to change video orientation.If it is true, then one can change the "orientation" property to the correct value (AVCaptureVideoOrientationPortrait, AVCaptureVideoOrientationLandscapeLeft, ...).Thanks for putting me in the good direction !
super_tomtom
Whoops! Missed the read-only part. Glad it helped.
christo16