我需要在菜单栏应用程序中调整 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)
}
最佳答案
PopoverResize 允许用户调整菜单栏 NSPopover 的大小。它还包括边缘光标。
关于swift - 在菜单栏应用程序中拖动并调整我的 NSPopover 大小(快速),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46631080/