【发布时间】: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