the simple code as follow:
// see xcdoc://?url=developer.apple.com/library/etc/redirect/xcode/mac/34580/documentation/GraphicsImaging/Conceptual/ImageKitProgrammingGuide/ImageBrowser/ImageBrowser.html
func setCommonValuesForKeys(allowsVideoCapture: Bool) {
/* use - (void) setValue:(id)aValue forKey:(id) aKey (NSKeyValueCoding) to customize the pictureTaker panel appearance and behaviors
*
* <key> <class> <default>
* IKPictureTakerAllowsVideoCaptureKey NSNumber(BOOL) YES
* IKPictureTakerAllowsFileChoosingKey NSNumber(BOOL) YES
* IKPictureTakerShowRecentPictureKey NSNumber(BOOL) YES
* IKPictureTakerUpdateRecentPictureKey NSNumber(BOOL) YES
* IKPictureTakerAllowsEditingKey NSNumber(BOOL) YES
* IKPictureTakerShowEffectsKey NSNumber(BOOL) NO
* IKPictureTakerInformationalTextKey NSString or NSAttributedString "Drag Image Here"
* IKPictureTakerImageTransformsKey NSDictionary(serializable) none
* IKPictureTakerOutputImageMaxSizeKey NSValue(NSSize) none
* IKPictureTakerShowAddressBookPictureKey NSNumber(BOOL) NO
* IKPictureTakerShowEmptyPictureKey NSImage nil
* IKPictureTakerRemainOpenAfterValidateKey NSNumber(BOOL) NO
*/
IKPictureTaker.pictureTaker().setValuesForKeys(
[
IKPictureTakerShowEffectsKey: NSNumber(booleanLiteral: true),
IKPictureTakerAllowsVideoCaptureKey: NSNumber(booleanLiteral: allowsVideoCapture),
IKPictureTakerAllowsFileChoosingKey: NSNumber(booleanLiteral: true),
IKPictureTakerShowRecentPictureKey: NSNumber(booleanLiteral: true),
IKPictureTakerUpdateRecentPictureKey: NSNumber(booleanLiteral: true),
IKPictureTakerAllowsEditingKey: NSNumber(booleanLiteral: true),
IKPictureTakerImageTransformsKey: NSDictionary(),
IKPictureTakerShowAddressBookPictureKey: NSNumber(booleanLiteral: true),
IKPictureTakerShowEmptyPictureKey: nil,
IKPictureTakerInformationalTextKey: "Drop an Image Here",
IKPictureTakerOutputImageMaxSizeKey: NSValue(size: NSSize(width: 40000, height: 40000))
]
)
}
func closeForInstance(_ instance: Any?) {
guard let instance = instance, isPointForInstance(instance) else { return }
close()
}
private func isPointForInstance(_ instance: Any) -> Bool {
guard let currentDelegate = delegate else { return false }
return instance as AnyObject === currentDelegate as AnyObject
}
}
class ViewController: NSViewController {
@IBOutlet weak var xx: NSImageView!
@IBOutlet weak var imageV: NSImageView!
@IBOutlet weak var btn: NSButton!
@IBAction func btnH(_ sender: NSButton) {
IKPictureTaker.pictureTaker().popUpRecentsMenu(
for: sender,
withDelegate: self,
didEnd: #selector(pictureTakerDidEnd(_:returnCode:contextInfo:)),
contextInfo: nil
)
}
@objc func pictureTakerDidEnd(_ pictureTaker: IKPictureTaker, returnCode: Int, contextInfo: Any?) {
guard returnCode == NSApplication.ModalResponse.OK.rawValue,
let image = pictureTaker.outputImage() else { return }
xx.image = image
}
}