肖像视频到风景 [英] Portrait video to landscape

查看:80
本文介绍了肖像视频到风景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道像这样的问题可能已经存在但是为了像我这样的其他人我会继续问问

I am aware questions like this one may already be out there but for the sake of others like me I will go ahead and ask

我有一个应用程序是设置为仅允许纵向方向,但此设置会影响我的视频,因为我希望只有视频才能在横向播放。有没有一种方法可以添加到我的.m文件中以使其工作?这是我的代码;

I have a app that is set to only allow portrait orientation but this setting affects my videos as I would like only the videos to be able to play in landscape also. Is there a method I can add unto my .m file to make this work? Here is my code;

 #import "BIDVideosViewController.h"

 @interface BIDVideosViewController ()


 @end

 @implementation BIDVideosViewController

 @synthesize moviePlayer ;


 @synthesize tableList;


 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
 {
 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 if (self) {
    // Custom initialization
 }
 return self;
 }


 - (void)viewDidLoad
 {
 [super viewDidLoad];
 UITableView *table = [[UITableView alloc]initWithFrame:self.view.bounds];
 [table setDelegate:self];
 [table setDataSource:self];
 [self.view addSubview:table];
 tableList = [[NSMutableArray alloc] initWithObjects:@"Gangan",@"SwimGood",@"German Ice", nil];

 }

 - (void)didReceiveMemoryWarning
 {
 [super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
 }

 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
 return [tableList count];
 }

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
 static NSString *DisclosureButtonIdentifier = @"DisclosurebutotonIdentifier";
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DisclosureButtonIdentifier];
 if (cell == nil)
 {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DisclosureButtonIdentifier];
 }

 NSInteger row = [indexPath row];
 NSString *rowString = [tableList objectAtIndex:row];
 cell.textLabel.text = rowString;

 return cell;
 }




 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
{
    NSBundle *str = [tableList objectAtIndex:indexPath.row];
    if ([str isEqual:@"Gangan"])
    {
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *thePath = [bundle pathForResource:@"Gangan" ofType:@"mp4"];
        NSURL *theurl = [NSURL fileURLWithPath:thePath];
        moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];

        [moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
        [self.view addSubview:moviePlayer.view];
        [moviePlayer setFullscreen:YES];

        [moviePlayer play];
    }
    else if ([str isEqual:@"SwimGood"])
    {
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *thePath = [bundle pathForResource:@"SwimGood" ofType:@"mp4"];
        NSURL *theurl = [NSURL fileURLWithPath:thePath];
        moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
        [moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
        [self.view addSubview:moviePlayer.view];
        [moviePlayer setFullscreen:YES];

        [moviePlayer play];

    }
    else if ([str isEqual:@"German Ice"])
    {
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *thePath = [bundle pathForResource:@"German Ice" ofType:@"mp4"];
        NSURL *theurl = [NSURL fileURLWithPath:thePath];
        moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
        [moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
        [self.view addSubview:moviePlayer.view];
        [moviePlayer setFullscreen:YES];

        [moviePlayer play];
    }

   }
   }
   @end


推荐答案

在视图控制器.m文件中,您应该

In your view controller .m file, you should have

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

在那里你可以返回 YES 对于支持的方向,这将使您能够旋转视频。

There you can return YES for supported orientations, which will enable you to rotate video.

如果你使用UINavigationController,这个方法也不行,除非所有视图都由<$ c管理$ c> UINavigationController 实现 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 以同样的方式。

Also not that if you use UINavigationController, this aproach wont work, unless all views managed by UINavigationController implement - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation the same way.

同样在你的目标 - >你的项目 - >摘要中,你可以设置支持的方向。

Also in your Targets -> "You Project" -> Summary, you can set supported orientations.

编辑:
go 此处查看UIInterfaceOrientation。那里有你需要的常数。

go here an look for UIInterfaceOrientation. There you have constants you need.

我会这样写:

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

这篇关于肖像视频到风景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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