You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在macOS应用中集成与Preview一致的系统级照片编辑功能?

Integrating System-Native Photo Editing UI on macOS

Hey there! Great question—integrating that familiar photo editing UI (matching Apple Preview) into your macOS app is totally achievable, and third-party apps like Shotty are using official Apple APIs to pull it off. Here’s the breakdown:

Core API: PHContentEditingController

The key framework here is Photos.framework, specifically the PHContentEditingController protocol. This is Apple’s official way to let third-party apps leverage the system’s built-in photo editing interface, which is exactly what powers Preview’s editing tools. The UI and interaction logic you’re seeing in Shotty are directly provided by this API—developers can choose to disable certain tools (hence the missing buttons) while keeping the rest of the Preview-like experience intact.

Step-by-Step Implementation Basics

  • Request Photos Permissions: First, your app needs access to the user’s photo library. Add the required permission descriptions to your Info.plist:
    • NSPhotoLibraryUsageDescription (for reading photos)
    • NSPhotoLibraryAddUsageDescription (for saving edited photos)
  • Implement the Protocol: Conform to PHContentEditingController in a custom class. This involves handling key methods like:
    • canHandle(_ adjustmentData: PHAdjustmentData?): Use this to filter which editing tools your app supports (this is how you hide specific buttons/features).
    • startContentEditing(with contentEditingInput: PHContentEditingInput, placeholderImage: NSImage): Initialize the editing session with the target photo.
    • finishContentEditing(completionHandler: @escaping ((PHContentEditingOutput?) -> Void)): Save the edited result and pass it back to the Photos framework.
  • Trigger the Editing UI: When the user wants to edit a photo, request a PHContentEditingInput using PHAsset.requestContentEditingInput(with:options:completionHandler:), then present your PHContentEditingController instance—this will launch the system’s native editing interface automatically.

Are There New Frameworks?

As of 2024, Apple hasn’t released a dedicated new framework for this functionality. PHContentEditingController has been supported since macOS 10.13 and remains the official, stable way to integrate system-level photo editing.

Official Documentation

You can find comprehensive guides and reference docs by searching for PHContentEditingController in Apple’s Developer Documentation. The docs include sample code, permission best practices, and details on customizing the editing toolset to match your app’s needs.


内容的提问来源于stack exchange,提问作者Tom Strong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:06:41