【问题标题】:Make my UIViewController fullscreen in Objective-C在 Objective-C 中让我的 UIViewController 全屏显示
【发布时间】:2017-12-04 22:59:02
【问题描述】:

我有一个使用 XIB 文件(不是故事板)的 Objective C 项目。

我有一个 UIViewController 视图,我从播放视频的 AppDelegate.m 文件中午餐。我想让它全屏但标题 顶部的条正在显示,屏幕左侧有一条细白线。

如何让整个视频全屏播放。

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    VideoIntroViewController *videoIntroViewController = [[VideoIntroViewController alloc] initWithNibName:@"VideoIntroViewController" bundle:nil];
    videoIntroViewController.managedObjectContext = self.managedObjectContext;

    self.navigationController = [[UINavigationController alloc] initWithRootViewController:videoIntroViewController];
    self.window.rootViewController = self.navigationController;
    [self.window addSubview:self.navigationController.view];

    [self.window makeKeyAndVisible];

  return YES;
}

VideoIntroViewController.m

- (void)viewWillAppear:(BOOL)animated
{   
    [super viewWillAppear:animated];

    if (!self.navigationController.toolbarHidden)
    {
        [self.navigationController setToolbarHidden:YES animated:animated];
    }
}

- (void)viewDidLoad
{
    [self createVideoPlayer];

    [super viewDidLoad];
}

- (void)createVideoPlayer
{
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"welcome_video" ofType:@"mp4"];
    NSURL *url = [NSURL fileURLWithPath:filePath];

    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];

    self.player = [AVPlayer playerWithPlayerItem:playerItem];
    self.player.volume = PLAYER_VOLUME;

    AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
    playerLayer.videoGravity = UIViewContentModeScaleToFill; <-- 'Null passed to a callee that requires a non-null argument'
    playerLayer.frame = self.playerView.layer.bounds;
    [self.playerView.layer addSublayer:playerLayer];

    [self.player play];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayDidEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:self.player.currentItem];
}

【问题讨论】:

  • 不要将根视图控制器的视图添加为窗口的子视图。改为设置窗口的rootViewController 属性。如果你不想要导航栏,为什么要使用导航控制器?

标签: ios objective-c


【解决方案1】:

在 AppDelegate 本身中隐藏导航栏:

self.navigationController = [[UINavigationController alloc] initWithRootViewController:videoIntroViewController];
self.navigationController.navigationBar.hidden = YES;

【讨论】:

    【解决方案2】:

    设置导航栏隐藏:

    self.navigationController.navigationBar.hidden = true;
    

    【讨论】:

      【解决方案3】:

      删除以下行,

      [self.window addSubview:self.navigationController.view];
      

      你已经设置了self.window的rootViewController。

      如果您需要添加子视图(此处不需要)并且您在该视图控制器/视图上使用自动布局,则必须在 storyboard/xib 文件中添加约束或为该视图编写代码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-09-25
        • 1970-01-01
        • 2012-06-05
        • 1970-01-01
        • 1970-01-01
        • 2012-04-24
        • 1970-01-01
        相关资源
        最近更新 更多