【发布时间】:2017-10-08 12:25:15
【问题描述】:
我需要在菜单栏应用中调整 NSPopver 的大小。这是我的方法:
override func mouseDragged(with event: NSEvent) {
let appDelegate : AppDelegate = NSApplication.shared().delegate as! AppDelegate
let originSize = appDelegate.popover.contentSize
let currentLocation = NSWindow().mouseLocationOutsideOfEventStream
let delta_x = NSWindow().mouseLocationOutsideOfEventStream.x - currentLocation.x
let delta_y = NSWindow().mouseLocationOutsideOfEventStream.y - currentLocation.y
let newWidth = originSize.width + delta_x
let newHeight = originSize.height + delta_y
appDelegate.popover.contentSize = NSSize(width: newWidth, height: newHeight)
}
问题:
- NSPopover 调整大小操作无法准确执行。
- 我希望当光标悬停到 NSPopover 边框时光标变为箭头,我该如何实现?
编辑:
我已经尝试NSPopOver & NSViewController - Drag to resize解决方案:
这里是转换为 swift3 版本的代码:
override func mouseDragged(with event: NSEvent) {
var currentLocation = NSEvent.mouseLocation()
var newOrigin = currentLocation
let screenFrame = NSScreen.main()?.frame
newOrigin.x = screenFrame!.size.width - currentLocation.x
newOrigin.y = screenFrame!.size.height - currentLocation.y
// Don't let window get dragged up under the menu bar
if newOrigin.x < 260 {
newOrigin.x = 260
}
if newOrigin.y < 300 {
newOrigin.y = 300
}
let appDelegate : AppDelegate = NSApplication.shared().delegate as! AppDelegate
appDelegate.popover.contentSize = NSSize(width: newOrigin.x, height: newOrigin.y)
}
【问题讨论】:
-
我试过他的解决方案,但是没有用,你能帮帮我吗?
-
你能描述一下它到底是怎么不工作的,或者你的情况与那个有什么不同吗?
-
你好,我编辑了我的问题,请给我一些建议。
标签: swift macos resize nspopover