我刚认识斯威夫特,而可可,来自JavaFX的背景。我在Xcode 6.1中构建了我的第一个Mac应用程序,它使用了一个AVPlayerView。我已经将AVPlayerView配置为提供了一个全屏按钮。当播放视频时,按下全屏图标会使播放器转到全屏。我正在寻找一种方法,使转义按钮使AVPlayerView返回到非全屏。
到目前为止,这是我的代码:
//subclassed AVPlayerView in an attempt to capture keystrokes
class VideoPlayerView: AVPlayerView, NSWindowDelegate {
var lastPlayValue = true //used in toggling play on space
var ifs = false; //variable holding "is full screen"
//overrode this to get keystrokes
override var acceptsFirstResponder: Bool {
return true
}
//thought this would be called when full screen is entered
//but it isn't
func windowDidEnterFullScreen(notification: NSNotification) {
ifs = true
println("Entered full screen")
//attempting to grab keyevents while in full screen
becomeFirstResponder()
}
//thought this would be called when full screen has exited
//but it isn't
func windowDidExitFullScreen(notification: NSNotification) {
ifs = false;
//attempting to grab key events after full screen exited
becomeFirstResponder()
println("Exited Fullscreen")
}
//grabs key events. Works when not in full screen mode
override func keyUp(theEvent: NSEvent) {
//handle events here.
}
}我的问题是: 1)当视频进入全屏时,VideoPlayerView似乎失去了焦点。2)我无法检测到视频已转到全屏( windowDidEnter方法不触发),3)我无法检测视频是否已离开全屏( windowDidExit方法没有启动)
另外,当我学习可可和Swift的时候,请告诉我这种方法是否正确。
如有任何帮助或指示,我们将不胜感激。
谢谢
新信息:--我已经注册了所有要进入全屏的视图的通知,但从未收到过。在仔细检查AVPlayerView的“全屏”之后,它似乎模仿了全屏的特性,而不是真正的“全屏”。
发布于 2014-11-06 13:48:19
所做的工作是不允许AVPlayerView上的全屏按钮,并通过我创建的按钮手动控制全屏功能。
发布于 2015-04-07 22:19:50
我也曾在AVPlayerView上经历过这个问题。如果像这样启用全屏按钮:
self.playerView.showsFullScreenToggleButton = YES;我点击全屏按钮视频进入全屏,然而,应用程序不接受任何关键输入,你不能激活任务Montrol,LaunchPad等。这是一个非常糟糕的用户体验,我相信如果你向Mac提交这样的应用程序,它将被拒绝。同时,我也试图让我的AVPlayerView成为第一个响应者,但没有效果。
解决方案
因此,我研究了QuickTime播放器在全屏播放视频方面的工作原理。我注意到它在播放器控件上没有一个全屏按钮。它处理全屏的方式是,当用户点击窗口的全屏控件时,它会调整窗口的大小,如果我是正确的,AVPlayerView或苹果正在使用的任何东西。要实现类似的内容,请执行以下操作:
//The window that contains your AVPlayerView set the delegate
[self.window setDelegate:self];
//So you can respond to these notifications
- (void)windowDidEnterFullScreen:(NSNotification *)notification{
// wait a bit
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.playerView.isReadyForDisplay == YES) {
//Make sure the playerView is ready for display
//Set the playerView to the screen's current frame (Very Important!)
[self.playerView setFrame:[[NSScreen mainScreen] frame]];
//Do other UI related things here e.g hide elements e.t.c
}
});
}
- (void)windowWillExitFullScreen:(NSNotification *)notification{
//Do other UI related things here e.g show elements e.t.c
}
//If you have a ToolBar in your application do this:
- (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
{
return (NSApplicationPresentationFullScreen |
NSApplicationPresentationHideDock |
NSApplicationPresentationAutoHideMenuBar |
NSApplicationPresentationAutoHideToolbar);
}
// To determine if the window is in fullscreen e.g. if the application opened/restored in a fullscreen state the windowDidEnterFullScreen will not be called. So you need to do this:
- (BOOL) isFullScreenMode {
NSApplicationPresentationOptions opts = [[NSApplication sharedApplication ] presentationOptions];
if ( opts & NSApplicationPresentationFullScreen) {
return YES;
}
return NO;
}结论
我希望这能回答你的问题。另外,我认为这是苹果的一个bug,所以我将在明天提交一份bug报告。
https://stackoverflow.com/questions/26557636
复制相似问题