0

好吧伙计们和其他人一样的问题。如果我编辑 .plist 以支持所有方向,我就能让它工作,但我只需要在我的 MPMoviePlayerController 上支持旋转(也许在我的 MWPhotoBrwoser 图像上)

我的代码:Viewcontroller.h

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>

@interface MusikViewController : UIViewController{
    AVAudioPlayer *audioPlayer;

}

//tilføjer vores film afspiller
@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;


//Laver de to knapper
//Musik knap
- (IBAction)Play:(UIButton *)sender;
//Film knap
- (IBAction)playButton:(id)sender;

//info knap
- (IBAction)info:(id)sender;


@end

视图控制器.m

#import "MusikViewController.h"



@implementation MusikViewController
@synthesize moviePlayer;


- (IBAction)Play:(UIButton *)sender
{
    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/roteWeste.mp4", [[NSBundle mainBundle] resourcePath]]];

    NSError *error;
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    audioPlayer.numberOfLoops = -1;

    if (audioPlayer == nil){
        NSLog(@"Der skete en fejl, prøv at genstarte app'en, hvis problemet bliver ved, prøv da at send en mail til Mrostgaard@gmail.com");
    }
    else
        [audioPlayer play];
}

- (IBAction)playButton:(id)sender {

    NSString *videoFile = [[NSBundle mainBundle] pathForResource:@"RoteVeste2" ofType:@"m4v"];

    moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:videoFile]];

    [self.view addSubview:moviePlayer.view];

    moviePlayer.fullscreen = YES;

    moviePlayer.allowsAirPlay = YES;
    moviePlayer.controlStyle = MPMovieControlModeVolumeOnly;


    [moviePlayer play];


}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        if ((UIDeviceOrientationIsLandscape(interfaceOrientation))||(UIDeviceOrientationIsLandscape(interfaceOrientation))) {
            return YES;
        }
        else return NO;
    }
    else
    {
        if ((UIDeviceOrientationIsLandscape(interfaceOrientation))||(UIDeviceOrientationIsLandscape(interfaceOrientation))) {
            return YES;
        }
        else return NO; }
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [audioPlayer stop]; // Or pause
}


- (IBAction)info:(id)sender {
}
@end

我似乎无法让它工作。编码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        if ((UIDeviceOrientationIsLandscape(interfaceOrientation))||(UIDeviceOrientationIsLandscape(interfaceOrientation))) {
            return YES;
        }
        else return NO;
    }
    else
    {
        if ((UIDeviceOrientationIsLandscape(interfaceOrientation))||(UIDeviceOrientationIsLandscape(interfaceOrientation))) {
            return YES;
        }
        else return NO; }
}

只是我最近的尝试,但我几乎尝试了所有方法只需要旋转 MPMovieViewController。

我什至试过这个,无法让它工作 http://fostah.com/ios/2012/09/27/ios6-orientation-handling.html

真心希望能得到帮助!:)

4

2 回答 2

1

在阅读您的问题时:“如果我编辑 .plist 以支持所有方向,我就可以使用它,但我只需要在我的 MPMoviePlayerController (也许在我的 MWPhotoBrwoser 图像)支持旋转”,第一句话是你应该允许 .plist 中的所有方向。plist 中允许的方向应该是应用程序中不同视图控制器必须支持的所有方向的联合。

无论您在特定视图控制器中做什么,您将永远无法允许旋转到您的 plist 中不允许的方向。

然后由所有单独的视图控制器来说明特定视图控制器允许的方向。所以分步骤:

  1. 允许 plist 中至少一个视图控制器支持的所有方向
  2. 对于所有单独的视图控制器,使用shouldAutorotateToInterfaceOrientation(iOS5) 和 shouldAutorotate/ supportedInterfaceOrientations(iOS6)
于 2012-12-10T10:16:09.233 回答
0

在 AppDelegate.h 中添加以下方法

-(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{

    if(!ISIPAD)){

        if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]] && ![[self.window.rootViewController presentedViewController] isBeingDismissed])
        {
            return UIInterfaceOrientationMaskAllButUpsideDown;
        }
        else
        {
            return UIInterfaceOrientationMaskPortrait;
        }
    }
    return UIInterfaceOrientationMaskAllButUpsideDown ;

}
于 2015-07-22T14:12:34.057 回答