我是 swift 和 Cocoa 的新手,具有 JavaFX 背景。我在 Xcode 6.1 中构建了我的第一个 Mac OS 应用程序,它使用了一个 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 方法未触发)
另外,由于我正在学习 Cocoa 和 Swift,请让我知道这种方法是否走在正确的轨道上。
感谢任何帮助或指点。
谢谢
新信息: 我已经注册了任何全屏 View 的通知,但从未收到过通知。在仔细检查 AVPlayerView 进入“全屏”后,它似乎模仿了全屏的特征,而不是真正的“全屏”。
最佳答案
我也遇到过 AVPlayerView 的这个问题。如果我像这样启用全屏按钮:
self.playerView.showsFullScreenToggleButton = YES;
然后我点击全屏按钮,视频进入全屏,但是,该应用程序不接受任何按键输入,您无法激活 Mission Montrol、LaunchPad 等。这是非常糟糕的用户体验,我相信如果您向 Mac App Store 提交这样的应用程序,它将被拒绝。我也试图让我的 AVPlayerView 成为第一响应者,但无济于事。
因此,我研究了 QuickTime Player 如何在全屏显示视频方面发挥作用。我注意到它在播放器控件上没有全屏按钮。它处理全屏的方式是,当用户单击窗口的全屏控件时,它会重新调整窗口的大小,如果我是正确的 AVPlayerView 或 Apple 使用的任何内容。要实现与此类似的操作,请执行以下操作:
//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;
}
我希望这能回答您的问题。另外,我认为这是 Apple 方面的错误,所以我明天会提交错误报告。
关于macos - 需要 AVPlayerView 在按下 esc 按钮时退出全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26557636/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Rubysyntaxquestion:Rational(a,b)andRational.new!(a,b)我正在阅读ruby镐书,我对创建有理数的语法感到困惑。Rational(3,4)*Rational(1,2)产生=>3/8为什么Rational不需要new方法(我还注意到例如我可以在没有new方法的情况下创建字符串)?
我希望用户从一个模型的三个选项中选择一个。即我有一个模型视频,可以被评为正面/负面/未知目前我有三列bool值(pos/neg/unknown)。这是处理这种情况的最佳方式吗?为此,表单应该是什么样的?目前我有类似的东西但显然它允许多项选择,而我试图将它限制为只有一个..怎么办? 最佳答案 如果要使用字符串列,让我们说rating。然后在你的表单中:#...#...它只允许一个选择编辑完全相同但使用radio_button_tag: 关于ruby-on-rails-Rails单选按钮-模
我需要用任何语言编写一个算法,根据3个因素对数组进行排序。我以度假村为例(如Hipmunk)。假设我想去度假。我想要最便宜的地方、最好的评论和最多的景点。但是,显然我找不到在所有3个中都排名第一的方法。Example(assumingthereare20importantattractions):ResortA:$150/night...98/100infavorablereviews...18of20attractionsResortB:$99/night...85/100infavorablereviews...12of20attractionsResortC:$120/night
修改(澄清问题)我已经花了几天时间试图弄清楚如何从Facebook游戏中抓取特定信息;但是,我遇到了一堵又一堵砖墙。据我所知,主要问题如下。我可以使用Chrome的检查元素工具手动查找我需要的html-它似乎位于iframe中。但是,当我尝试抓取该iframe时,它是空的(属性除外):如果我使用浏览器的“查看页面源代码”工具,这与我看到的输出相同。我不明白为什么我看不到iframe中的数据。答案不是它是由AJAX之后添加的。(我知道这既是因为“查看页面源代码”可以读取Ajax添加的数据,也是因为我有b/c我一直等到我可以看到数据页面之后才抓取它,但它仍然不存在)。发生这种情况是因为
我想从rubyrake脚本运行一个可执行文件,比如foo.exe我希望将foo.exe的STDOUT和STDERR输出直接写入我正在运行rake任务的控制台.当进程完成时,我想将退出代码捕获到一个变量中。我如何实现这一目标?我一直在玩backticks、process.spawn、system但我无法获得我想要的所有行为,只有部分更新:我在Windows上,在标准命令提示符下,而不是cygwin 最佳答案 system获取您想要的STDOUT行为。它还返回true作为零退出代码,这可能很有用。$?填充了有关最后一次system调
这个问题在这里已经有了答案:HashsyntaxinRuby[duplicate](1个回答)关闭5年前。我有一个Recipe,其中包含以下未通过lint测试的代码:service'apache'dosupports:status=>true,:restart=>true,:reload=>trueend失败并出现错误:UsethenewRuby1.9hashsyntax.supports:status=>true,:restart=>true,:reload=>true不确定新语法是什么样的...有人可以帮忙吗?
我的问题很简单:我是否必须在使用RubyonRails的类上require'csv'?如果我打开一个railsconsole并尝试使用CSVgem它可以工作,但我必须在文件中这样做吗? 最佳答案 CSVlibrary是ruby标准库的一部分;它不是gem(即第三方库)。与所有标准库(与核心库不同)一样,csv不会由ruby解释器自动加载。所以是的,在您的应用程序中某处您确实需要要求它:irb(main):001:0>CSVNameError:uninitializedconstantCSVfrom(irb):1from/Us