在 Safari 中,我可以将项目(例如 URL,甚至是取景器中的 .webloc 书签)直接拖到选项卡上以打开。
\n如何使窗口选项卡栏项目在我自己的 AppKit 应用程序中查看放置目标?
\nI\xe2\x80\x99d 希望能够接受删除NSPasteboard类似于NSView实例的方式:
override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {\n // Handle drop\n}\nRun Code Online (Sandbox Code Playgroud)\n但选项卡栏和包含的NSTabButton实例是由系统提供的。\n子类化或扩展NSTabButton\xe2\x80\x99 似乎不起作用,因为\xe2\x80\x99 是私有的。
我发现NSBundle中的NSNibLoading方法:
+[NSBundle loadNibFile:externalNameTable:withZone:]
+[NSBundle loadNibNamed:owner:]
-[NSBundle loadNibFile:externalNameTable:withZone:]
Run Code Online (Sandbox Code Playgroud)
已经在10.8中被标记为已弃用 - 在10.8及更高版本中加载笔尖的正确方法是什么?
我想在我的应用程序创建一个自定义纸张,我必须创建NSWindowController具有initWithWindowNibName自定义纸张?
我的一个项目是一个测试应用程序,学生在打字时不应该轻易查找单词.
通过setContinuousSpellCheckingEnabled:和关闭NSTextView中的自动拼写检查相对容易setAutomaticSpellingCorrectionEnabled:.
我刚刚发现,对于学生来说,只需用三根手指点击任何应用程序中的任何选定单词即可轻松弹出一个包含字典,词库甚至是维基百科条目的有用窗口,如果可以在那里找到该单词.

这是99%的MacOS应用程序的强大功能,但不适合我的测试应用程序.
现在几个月后,Apple为我提供了一个(无证件和微妙的)解决方案,仅适用于10.8,我最终可能会在下面的答案中提供它,但我需要一个适用于10.7的解决方案(其中是这个功能的来源).
对这个问题有三种可能的攻击计划,但我不确定如何处理这三种问题中的任何一种:
1)
我需要阻止此查找功能在此文本视图中发生.
2)
我已经尝试删除字典首选项(如果它们存在;如果用户从未打开Dictionary.app,没有首选项)和字典缓存文件(在" ~/Library/Cache"中,但这似乎没有改善情况.
3)
或者有没有办法能够检测到"在执行三指点击时使用查找"的"触控板"设置?它可能在某些com.apple.*.plist某处或可通过" defaults" 检测到但是我不确定在哪里.
编辑:
只剩下一点时间来希望解决这个问题并奖励一笔赏金.这是我尝试使用" defaults"的方法:
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadThreeFingerTapGesture -bool false
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadThreeFingerDoubleTapGesture -bool false
Run Code Online (Sandbox Code Playgroud)
但我并不是100%肯定这些是键入的正确手势/关键字.即使在输入后(并验证它们是通过" defaults read com.apple.driver.AppleBluetoothMultitouch.trackpad" 正确保存),字典LookUp窗口仍然会出现.
现在这里唯一可行的,但它只适用于MacOS 10.8(这是暴露/引入这些方法的地方).只需在NSTextView子类中覆盖这两个方法:
- (void)quickLookWithEvent:(NSEvent *)event;
- (void)quickLookPreviewItems:(id)sender;
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 python 中运行音频文件
from playsound import playsound
def main():
playsound('audio.mp3')
main()
Run Code Online (Sandbox Code Playgroud)
但是,我不断收到以下错误:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/playsound.py", line 55, in _playsoundOSX
from AppKit import NSSound
ImportError: No module named 'AppKit'
Run Code Online (Sandbox Code Playgroud)
我在 macOS 10.12.6 上使用 Python 3.5.4。我曾尝试通过 pip 安装它,但返回此错误:
Using cached AppKit-0.2.8.tar.gz
Requirement already satisfied: flask in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from appkit)
Collecting pygobject (from appkit)
Could not find a version that satisfies the requirement pygobject (from appkit) (from versions: )
No matching distribution found for pygobject (from appkit)
Run Code Online (Sandbox Code Playgroud) 当NSWindow应该或将要关闭时,我该如何注意?我想要像windowWillClose这样的东西.不幸的是,NSWindowController没有像UIViewController那样方便的方法.那么这样做的最佳做法是什么?
谢谢
-f
嗨我在我的一个应用程序中实现了NSPopover,但popover不会关闭.我猜它应该在我点击其他东西时关闭,但事实并非如此.我知道有一个关闭的弹出操作,但只适用于不同的按钮.当我按下相同的按钮时,如何让它看到弹出窗口打开以及何时打开以关闭弹出窗口?
每当我尝试在UITextView的attributedText上设置下划线或删除线属性时,我都会遇到运行时故障.其他属性,如字体和背景颜色没有问题.这是一段代码片段.我所拥有的只是一个带有单个UITextView的测试项目.我在iOS 11上.
class ViewController: UIViewController {
@IBOutlet weak var myTextView: UITextView!
var myMutableString = NSMutableAttributedString(string: "")
override func viewDidLoad() {
super.viewDidLoad()
let string = "The cow jumped over the moon" as NSString
myMutableString = NSMutableAttributedString(string: string as String)
let underlineAttribute = [NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle]
myMutableString.addAttributes(underlineAttribute, range: string.range(of: "cow"))
myTextView.attributedText = myMutableString
}
}
Run Code Online (Sandbox Code Playgroud)
这导致文本消失并打印出一些错误:
2017-11-05 19:43:34.708830-0800 UITextView_Test[11771:907014]
-[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance 0x60c00004eb50 2017-11-05 19:43:34.709351-0800 UITextView_Test[11771:907014] <NSATSTypesetter: 0x60800016be80>: Exception -[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance 0x60c00004eb50 raised during …Run Code Online (Sandbox Code Playgroud) 我遇到了一个问题,后台应用程序使用LSUIElement = 1隐藏其停靠项,菜单栏并阻止它出现在Command-Tab应用程序切换器中.
它似乎只是雪豹的问题.
应用程序在菜单栏中放置一个NSStatusItem,并在单击时弹出一个菜单.选择"首选项..."应该会显示带有首选项的NSWindow.
第一件似乎不起作用的是Window没有在前面订购,而是出现在所有其他应用程序窗口后面.
我试着通过打电话来解决这个问题
[[NSApplication sharedApplication] activateIgnoringOtherApps: YES]
Run Code Online (Sandbox Code Playgroud)
但那没用.
过了一会儿,我发现菜单阻止了发送到运行循环的消息,所以我在MainController上编写了另一个方法,并发送了延迟消息:
[self performSelector:@selector(setFront :) withObject:[preferencesController window] afterDelay:1.0];
-(void)setFront: (id) theWindow {
[[NSApplication sharedApplication]activateIgnoringOtherApps:YES];
[theWindow orderFrontRegardless];
[theWindow makeKeyWindow];
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
}
Run Code Online (Sandbox Code Playgroud)
请注意send-every-possible-message-to-make-it-do-it-it-it-doing-doing方法.
这种方式有点好,窗口在所有应用程序的所有其他窗口的顶部被带到前面,但大部分时间它都不活动,这意味着它的标题栏是灰色的.单击标题栏也不会使窗口处于活动状态.单击窗口的内部将激活它!?
这一切似乎都不是豹子的问题; 只是调用activateIgnoringOtherApps并使窗口键似乎工作正常.
在Snow Leopard中有一个新的API,用于替换应该模拟其行为的LSUIElement:
http://developer.apple.com/mac/library/releasenotes/cocoa/appkit.html
我玩过这个,但它只是SL而且我无法设置LSUIElement.
我查看了安全框架文档,但我似乎无法找到一种方法来获取给定钥匙串上的所有证书.有没有办法来实现这个目标?
我试图在我实现的聊天历史视图中实现平滑滚动,但是如果我追加的内容足够大,则平滑滚动只会滚动几行.
我的第一个猜测是视图没有重绘自己..不是这样,即使用-display强制立即绘图它仍然会破坏.
- (void)scrollAnimated:(BOOL)animated
{
if( animated )
{
NSClipView *clipView = [[_chatHistoryView enclosingScrollView] contentView];
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.100f];
NSPoint constrainedPoint = [clipView constrainScrollPoint:NSMakePoint(0, CGFLOAT_MAX)];
[[clipView animator] setBoundsOrigin:constrainedPoint];
[NSAnimationContext endGrouping];
}
else
{
NSRange range;
range.location = [[_chatHistoryView textStorage] length];
range.length = 1;
[_chatHistoryView scrollRangeToVisible:range];
}
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?