首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅限AutoRotate MpMoviePlayerControler iOS 6

仅限AutoRotate MpMoviePlayerControler iOS 6
EN

Stack Overflow用户
提问于 2012-12-08 08:31:46
回答 2查看 1.7K关注 0票数 0

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

我的代码:ViewControler.h

代码语言:javascript
复制
#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

Viewcontroller.m

代码语言:javascript
复制
#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

我就是不能让它工作。代码:

代码语言:javascript
复制
- (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

真的希望能得到一些帮助!:)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-10 18:16:09

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

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

然后由所有单独的视图控制器来决定特定的视图控制器允许什么方向。因此,在步骤中:

  1. 允许plist中至少有一个视图控制器支持的所有方向对于所有单个视图控制器,请使用shouldAutorotateToInterfaceOrientation (iOS5)

shouldAutorotate / supportedInterfaceOrientations (iOS6)

票数 1
EN

Stack Overflow用户

发布于 2015-07-22 22:12:34

在AppDelegate.h中添加以下方法

代码语言:javascript
复制
-(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 ;

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13773179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档