肖像视频到风景



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

我有一个仅允许肖像方向的应用程序,但是这种设置会影响我的视频,因为我只希望视频也能够在景观中播放。我可以将一种方法添加到.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

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

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

您可以返回YES以进行支持的方向,这将使您旋转视频。

也不是,如果您使用uinavigation controller,则此审议将无法使用,除非UINavigationController管理的所有视图以相同的方式实现- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

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

编辑:去这里查看uiinterfaceorientation。您有您需要的常数。

我会这样写:

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

最新更新