iPhone应用程序-在横向模式下显示AVFoundation视频 [英] iPhone App - Show AVFoundation video on landscape mode

查看:104
本文介绍了iPhone应用程序-在横向模式下显示AVFoundation视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apple的AVCam示例应用程序.

I am using the AVCam example App from Apple.

此示例使用AVFoundation以便在视图上显示视频.

This example uses AVFoundation in order to show video on a view.

我正在尝试从AVCam制作一款运气不好的风景应用程序.

I am trying to make from the AVCam a landscape App with no luck.

当屏幕方向改变时,视频在视图上旋转显示.有没有办法解决这个问题?

When screen orientation changes the video is shown rotated on the view. Is there a way of handling this problem?

推荐答案

创建预览层时:

captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;

以及管理轮换的方法:

-(void)willAnimateRotationToInterfaceOrientation:
        (UIInterfaceOrientation)toInterfaceOrientation 
        duration:(NSTimeInterval)duration {

  [CATransaction begin];
  if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft){
    captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
  } else {        
    captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
  }

 [CATransaction commit];
 [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

-(BOOL)shouldAutorotateToInterfaceOrientation:
        (UIInterfaceOrientation)interfaceOrientation {

  [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];

  return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

对我有用.

这篇关于iPhone应用程序-在横向模式下显示AVFoundation视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆