Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming your previewlayer is added to a viewcontroller view. Do this in <code>viewDidLoad</code> :</p> <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; </code></pre> <p>and define the selector as: </p> <pre><code>- (void)orientationChanged:(NSNotification*)notification { UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation; if ([self.previewlayer respondsToSelector:@selector(orientation)]) { //for iOS5 if (interfaceOrientation != UIInterfaceOrientationPortrait) { self.previewlayer.orientation = (AVCaptureVideoOrientation)UIInterfaceOrientationPortrait; } } else { //for iOS6 if (interfaceOrientation != UIInterfaceOrientationPortrait) { self.previewlayer.connection.videoOrientation = (AVCaptureVideoOrientation)UIInterfaceOrientationPortrait; } } } </code></pre> <p><strong>Note:</strong> put <code>tempPreviewLayer</code> in the property <code>self.previewlayer</code> .</p> <p>This will force the preview layer to portrait position when the device orientation changes.</p> <p><strong>EDIT</strong></p> <p>you can also add this in ur 'shouldAutoRotate` method of the viewController</p> <pre><code> - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations if ([self.previewlayer respondsToSelector:@selector(orientation)]) { if (interfaceOrientation != UIInterfaceOrientationPortrait) { self.previewlayer.orientation = (AVCaptureVideoOrientation)UIInterfaceOrientationPortrait; } } else { if (interfaceOrientation != UIInterfaceOrientationPortrait) { self.previewlayer.connection.videoOrientation = (AVCaptureVideoOrientation)UIInterfaceOrientationPortrait; } } return (interfaceOrientation == UIInterfaceOrientationPortrait); } </code></pre> <p>for ios6 over ride these two and check.</p> <pre><code>-(NSUInteger)supportedInterfaceOrientations { //UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation; //return ( //interfaceOrientation == UIInterfaceOrientationLandscapeLeft | //interfaceOrientation == UIInterfaceOrientationLandscapeRight); return UIInterfaceOrientationMaskLandscape;//(UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight); } - (BOOL)shouldAutorotate { return YES; } </code></pre> <p>before <code>return</code> in these two methods apend the code ..and in the notification that i gave, see if its called when you roate the device.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload