【问题标题】:Landscape mode only when playing video. xcode. ios 7横向模式仅在播放视频时。代码。 IOS 7
【发布时间】:2014-10-10 09:06:42
【问题描述】:

我使用 youtube-ios-player-helper:https://github.com/youtube/youtube-ios-player-helperhttps://developers.google.com/youtube/v3/guides/ios_youtube_helper

我一切正常。视频播放很好! 但! 在项目设置中,我关闭了横向模式。因此,视频仅以纵向模式播放。在 iOS 7 中播放视频时如何打开横向模式?

【问题讨论】:

  • 您是否已经解决了这个问题? :)

标签: xcode video ios7 youtube landscape


【解决方案1】:

我的解决方案:

它适用于 iOS 7 和 iOS 8

为了播放 YouTube 上的视频,我使用了 XCDYouTubeKit (https://github.com/0xced/XCDYouTubeKit)

AppDelegate.h:

@property (nonatomic) BOOL screenIsPortraitOnly;

AppDelegate.m:

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

    if (!self.screenIsPortraitOnly) {
        return UIInterfaceOrientationMaskPortrait;
    }
    else {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
}

MYTableViewController.m:

#import "XCDYouTubeVideoPlayerViewController.h"
#import "XCDYouTubeKit.h"
#import "AppDelegate.h"

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:myIdYoutube];
    [[NSNotificationCenter defaultCenter] removeObserver:videoPlayerViewController  name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayerViewController.moviePlayer];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoFinished) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayerViewController.moviePlayer];
    videoPlayerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:videoPlayerViewController animated:YES completion:nil];
}

-(void)videoFinished
{
    AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    appDelegate.screenIsPortraitOnly = false;
    [self dismissViewControllerAnimated:YES completion:NULL];
}

XCDYouTubeVideoPlayerViewController.m

#import "AppDelegate.h"

- (instancetype) initWithVideoIdentifier:(NSString *)videoIdentifier
{
    AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    appDelegate.screenIsPortraitOnly = true;
    if ([[[UIDevice currentDevice] systemVersion] integerValue] >= 8)
        self = [super initWithContentURL:nil];
    else
        self = [super init];

    if (!self)
        return nil;

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];

    if (videoIdentifier)
        self.videoIdentifier = videoIdentifier;

    return self;
}

- (void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    appDelegate.screenIsPortraitOnly = false;

    if (![self isBeingDismissed])
        return;

    [self.videoOperation cancel];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-02
    • 2014-11-24
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 2014-11-21
    • 2013-06-15
    • 1970-01-01
    相关资源
    最近更新 更多