gpt4 book ai didi

ios - 纵向视频转横向

转载 作者:行者123 更新时间:2023-11-29 04:20:15 24 4
gpt4 key购买 nike

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

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

 #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

最佳答案

在你的 View Controller .m 文件中,你应该有

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

您可以在此处返回 YES 以获取受支持的方向,这将使您能够旋转视频。

另外,如果您使用 UINavigationController,这种方法将不起作用,除非 UINavigationController 管理的所有 View 都以相同的方式实现 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation .

此外,在“目标”->“您项目”->“摘要”中,您可以设置支持的方向。

编辑:去here查看 UIInterfaceOrientation。那里有你需要的常量。

我会这样写:

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

关于ios - 纵向视频转横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13065455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com