最新消息:iOS编程开发交流群(6906921) ,Mac.Cocoa开发交流群(7758675) 欢迎iOS/macOS开发编程爱好及学习者加入!

AppKit Framework Reference

Cocoa 天狐 7100浏览 0评论

AppKit

Cocoa开发常用框架,用来在macOS构建和管理您的应用程序的用户界面。响应用户交互和系统事件、 启用辅助功能,以及处理文件、 文本和图像。

概述

AppKit是一个包含你需要的所有对象,比如实现图形化,事件驱动的用户界面:windows、 面板、 按钮、 菜单、 滚动条、 和文本框。AppKit 为您处理所有的细节,为它有效地绘制在屏幕上。与硬件设备和屏幕缓冲区进行通信,绘图前清除屏幕区域和剪切视图。很多 AppKit 的类可能第一次看起来令人生畏。然而,大多数的 AppKit 类是您间接使用的支持类。你也有在哪一级使用 AppKit 的选择:

  • 使用 Interface Builder来创建用户界面对象到你的应用程序对象的链接。在这种情况下,你需要做的就是执行应用程序的类 — — 执行这些action和delegate的方法。例如,实现当用户选择菜单项时调用的方法。
  • 以编程方式控制的用户界面,这需要更多的熟悉 AppKit 类和protocols协议。例如,允许用户将图标从一个窗口拖到另一个需要一些编程并且熟悉 NSDragging...协议。
  • 通过设置 NSView 或其他类的子类来实现您自己的对象。当子类化 NSView 要你使用图形函数自己实现绘图的方法。子类化需要 AppKit 的工作原理有更深理解。

若要了解更多关于 AppKit,请查看NSApplication、 NSWindow 和 NSView 类,密切关注delegate方法。AppKit 的工作原理的深入了解,请参阅 NSResponder 和 RunLoop (NSRunLoop 在基础框架中)。

AppKit 类和协议

AppKit非常大,它包括超过 125 个类和协议。所有类都从基础框架 NSObject 类派生。下面简要描述AppKit其类和协议的一些主题。

封装Application

每个应用程序使用单个实例的 NSApplication 控制主事件循环,保持应用程序的窗口和菜单跟踪、 分发到相应的对象 (即,本身或其窗口之一) 事件、 autorelease 池设置和接收应用程序级别事件的通知。NSApplication 对象具有一个delegate(一个你分配的对象),当应用程序启动或终止,隐藏或激活,打开用户选定的文件等等会被通知。通过设置 NSApplication 对象delegate和你实现delegate方法,可以自定义您的应用程序的行为而不必子类化 NSApplication。

一般事件处理和绘图

NSResponder 类定义响应链,响应用户事件的对象的有序表。当用户单击鼠标按钮或按下一个键时,事件将生成并在响应链传递 寻找可以"回应"的对象。处理事件的任何对象必须从 NSResponder 类继承。核心 AppKit 类,NSApplication、 NSWindow 和 NSView,都是从 NSResponder 继承。

NSApplication 对象维护一个 NSWindow 对象列表 — — 一个用于每个属于应用程序的窗口 — — 与每个 NSWindow 对象维护 NSView 对象层次结构。视图层次结构用来在window内画图和处理事件窗口。NSWindow 对象处理窗口级别的事件、 将其他事件分发给他的视图 提供绘图区域给视图。NSWindow 对象还具有一个delegate,允许您自定义其行为。

NSView 是显示在一个窗口中的所有对象的抽象类。所有的子类实现绘图的方法,图形方法draw(_:) 是在创建一个新的 NSView 子类时覆盖的主要方法。

面板

NSPanel是NSWindow的子类, 类是您使用来显示瞬态、 全局或紧迫的信息。例如,您将使用 NSPanel,一个实例,而不是实例的 NSWindow,来显示错误消息或查询用户对特殊的情况下作出的反应。AppKit 实现一些常见的面板为您,如保存,打开和打印面板,用于保存,打开和打印文件。使用这些面板为用户提供一个一致的"外观和视觉"跨应用程序的常见操作。

菜单和游标

NSMenu、 NSMenuItem 和 NSCursor 的类定义的外观和行为的菜单和应用程序向用户显示的光标。

分组和滚动视图

NSBox、 NSScrollView 和 NSSplitView 的类提供对其他视图对象或集合的视图窗口中图形的"附着"。 NSBox 类,你可以在 windows 中的元素分组和绘制整个组周围的边框。NSSplitView 类可以让你"堆栈"视图垂直或水平,分摊到每个视图一定范围,sliding control允许用户重新分配视图之间的范围。NSScrollView 类和它的帮助器,NSClipView,提供一种滚动机制,以及让用户发起和控制滚动的图形对象。NSRulerView 类允许你将一把尺子和标记添加到滚动视图。

控制应用程序

NSControl 和 NSCell 类和及其子类定义一套共同的用户界面对象,如按钮、 滑块和浏览器,用户可以以图形方式操作,来控制您的应用程序的某些方面。特定的控制会影响在于你自己︰ 当控制"touched"时,它将action消息发送到目标对象。你通常使用Interface Builder设置这些targets和actions,由控件拖动到您的应用程序的控制对象或其他对象。此外可以以编程方式设置targets和actions。

NSControl 对象是与实现细节的绘制和处理事件的一个或多个 NSCell 对象相关联。例如,一个按钮包括一个 NSButton 对象和一个 NSButtonCell 对象。这种功能的分离的原因,主要是以允许 NSCell 类 NSControl 类被重用。例如,NSMatrix 和 NSTableView 可以包含多个不同类型的 NSCell 对象。

NSTableView 类以行和列的形式显示数据。NSTableView 是理想的但不是限于,显示数据库记录,其中行对应于每条记录,列包含记录的属性。用户可以编辑单个单元格和列进行重新排列。通过设置其delegate和数据源对象,可以控制行为和 NSTableView 对象的内容。

文本和字体

NSTextField 类实现一个简单的可编辑的text field,并且 NSTextView 类提供了更全面的编辑功能,为了更大的文本body。

NSTextView,抽象的 NSText 类的子类,Cocoa的扩展文本系统定义的接口。NSTextView 支持富文本、 附件 (图形、 文件和其他),输入的管理和键绑定,可标记文本属性。NSTextView 与字体面板和菜单、 rulers和段落样式、 服务设施 (例如,拼写检查服务) 和粘贴板工作。NSTextView 还允许自定义through delegation和notifications — — 你很少需要子类 NSTextView。你很少以编程方式创建 NSTextView, 由于 Interface Builder调色板上的对象,如 NSTextField、 NSForm 和 NSScrollView,已经包含 NSTextView 对象。

它也是可以做到更强大、 更具创造性的文本操作 (如在一个圆圈中显示文本) 使用 NSTextStorage、 NSLayoutManager、 NSTextContainer 和相关的类。

NSFont 和 NSFontManager 类封装和管理字体系列、 大小和变化。NSFont 类定义单个对象为每个不同的字体;为了提高效率,这些对象共享在您的应用程序中。NSFontPanel 类定义字体规格面板,呈现给用户。

图形和颜色

少量的编程,自定义view对象可以在任何地方被拖拽,成为这种拖拽机制的一部分的对象遵循NSDragging……协议:可拖动的对象遵循NSDraggingSource协议,目标对象(接收器)遵循NSDraggingDestination协议,AppKit隐藏了光标跟踪的所有细节,并且显示图像。

打印

NSPrintPanel,NSPrinter NSPageLayout,NSPrintInfo类共同提供关于您的应用程序显示在窗口和视图的打印信息。您还可以创建一个EPS NSView表示。

访问文件系统

使用NSFileWrapper类创建对象对应于磁盘上的文件或目录。NSFileWrapper将文件的内容保留在内存中,以便它可以显示,改变,或传播到另一个应用程序。它还提供了一个图标给拖动文件或代表它作为一个附件。或使用NSFileManager类的基础框架来访问和枚举文件和目录的内容。NSOpenPanel NSSavePanel类还提供了一种方便和熟悉的用户界面到文件系统。

与其他应用程序共享数据

NSPasteboard类定义了剪切板,一个从你的app中拷贝的数据的仓库,使这些数据提供给任何愿意使用它的app。NSPasteboard实现类似剪切-复制-粘贴的操作。

NSServicesRequest协议通过使用剪切板之间传递的数据进行应用程序通信的注册服务。

检查拼写

NSSpellServer类使你定义拼写检查服务并且提供服务给其他app,连接你的app到拼写服务,使用NSSpellChecker类,NSIgnoreMisspelledWords 和 NSChangeSpelling protocols支持拼写检查的机制。

国际化

如果应用程序是用于在多个世界的地区,其资源可能需要自定义,或"本地化" 为本地语言。例如,应用程序可能需要有单独的日语、 英语、 法语和德语版本的字符串、 图标、 nib 文件或相关的帮助。具体到特定语言的资源文件 (扩展名为".lproj"目录) bundle目录的一个子目录中被组合在一起。通常您使用Interface Builder设置本地化资源文件。有关本地化和资源的更多信息,请参见Bundle

符号

Classes NSATSTypesetter
NSAccessibility​Element
NSAction​Cell
NSAlert
NSAlignment​Feedback​Filter
NSAnimation
NSAnimation​Context
NSAppearance
NSApplication
NSArray​Controller
NSBezier​Path
NSBitmap​Image​Rep
NSBox
NSBrowser
NSBrowser​Cell
NSButton
NSButton​Cell
NSCIImage​Rep
NSCandidate​List​Touch​Bar​Item
NSCell
NSClick​Gesture​Recognizer
NSClip​View
NSCollection​View
NSCollection​View​Flow​Layout
NSCollection​View​Flow​Layout​Invalidation​Context
NSCollection​View​Grid​Layout
NSCollection​View​Item
NSCollection​View​LayoutNSCollection​View​Layout​Attributes
NSCollection​View​Layout​Invalidation​Context
NSCollection​View​Transition​Layout
NSCollection​View​Update​Item
NSColor
NSColor​List
NSColor​Panel
NSColor​Picker
NSColor​Picker​Touch​Bar​Item
NSColor​Space
NSColor​Well
NSCombo​Box
NSCombo​Box​Cell
NSControl
NSController
NSCursor
NSCustom​Image​Rep
NSCustom​Touch​Bar​Item
NSData​Asset
NSDate​Picker
NSDate​Picker​Cell
NSDictionary​Controller
NSDictionary​Controller​Key​Value​Pair
NSDock​Tile
NSDocument
NSDocument​Controller
NSDragging​Image​Component
NSDragging​Item
NSDragging​Session
NSDrawer
NSEPSImage​Rep
NSEvent
NSFile​Promise​Provider
NSFile​Promise​Receiver
NSFont
NSFont​Collection
NSFont​Descriptor
NSFont​Manager
NSFont​Panel
NSForm
NSForm​Cell
NSGesture​Recognizer
NSGlyph​Generator
NSGlyph​Info
NSGradient
NSGraphics​Context
NSGrid​CellNSGrid​ColumnNSGrid​RowNSGrid​ViewNSGroup​Touch​Bar​Item
NSHaptic​Feedback​Manager
NSHelp​Manager
NSImage
NSImage​Cell
NSImage​Rep
NSImage​View
NSLayout​Anchor
NSLayout​Constraint
NSLayout​Dimension
NSLayout​Guide
NSLayout​Manager
NSLayout​XAxis​Anchor
NSLayout​YAxis​Anchor
NSLevel​Indicator
NSLevel​Indicator​Cell
NSMagnification​Gesture​Recognizer
NSMatrix
NSMedia​Library​Browser​Controller
NSMenu
NSMenu​Item
NSMenu​Item​Cell
NSMutable​Font​Collection
NSMutable​Paragraph​Style
NSNib
NSObject​Controller
NSOpen​GLContext
NSOpen​GLLayer
NSOpen​GLPixel​Format
NSOpen​GLView
NSOpen​Panel
NSOutline​View
NSPDFImage​Rep
NSPDFInfo
NSPDFPanel
NSPICTImage​Rep
NSPage​Controller
NSPage​Layout
NSPan​Gesture​Recognizer
NSPanel
NSParagraph​Style
NSPasteboardNSPasteboard​ItemNSPath​CellNSPath​Component​Cell
NSPath​Control
NSPath​Control​Item
NSPersistent​Document
NSPop​Up​Button
NSPop​Up​Button​Cell
NSPopover
NSPopover​Touch​Bar​Item
NSPredicate​Editor
NSPredicate​Editor​Row​Template
NSPress​Gesture​Recognizer
NSPressure​Configuration
NSPrint​Info
NSPrint​Operation
NSPrint​Panel
NSPrinter
NSProgress​Indicator
NSResponder
NSRotation​Gesture​Recognizer
NSRule​Editor
NSRuler​Marker
NSRuler​View
NSRunning​Application
NSSave​Panel
NSScreen
NSScroll​View
NSScroller
NSScrubber
NSScrubber​Arranged​ViewNSScrubber​Flow​LayoutNSScrubber​Image​Item​ViewNSScrubber​Item​ViewNSScrubber​LayoutNSScrubber​Layout​AttributesNSScrubber​Proportional​LayoutNSScrubber​Selection​StyleNSScrubber​Selection​ViewNSScrubber​Text​Item​View
NSSearch​Field
NSSearch​Field​Cell
NSSecure​Text​Field
NSSecure​Text​Field​Cell
NSSegmented​Cell
NSSegmented​Control
NSShadow
NSSharing​Service
NSSharing​Service​Picker
NSSharing​Service​Picker​Touch​Bar​Item
NSSlider
NSSlider​AccessoryNSSlider​Accessory​Behavior
NSSlider​Cell
NSSlider​Touch​Bar​Item
NSSound
NSSpeech​Recognizer
NSSpeech​Synthesizer
NSSpell​Checker
NSSplit​View
NSSplit​View​Controller
NSSplit​View​Item
NSStack​View
NSStatus​Bar
NSStatus​Bar​Button
NSStatus​Item
NSStepper
NSStepper​Cell
NSStoryboard
NSStoryboard​Segue
NSString​Drawing​Context
NSTab​View
NSTab​View​Controller
NSTab​View​Item
NSTable​Cell​View
NSTable​Column
NSTable​Header​Cell
NSTable​Header​View
NSTable​Row​View
NSTable​View
NSTable​View​Row​Action
NSText
NSText​Alternatives
NSText​Attachment
NSText​Attachment​Cell
NSText​Block
NSText​Container
NSText​Field
NSText​Field​Cell
NSText​Finder
NSText​Input​Context
NSText​List
NSText​Storage
NSText​Tab
NSText​Table
NSText​Table​Block
NSText​View
NSTitlebar​Accessory​View​Controller
NSToken​Field
NSToken​Field​Cell
NSToolbar
NSToolbar​Item
NSToolbar​Item​Group
NSTouch
NSTouch​Bar
NSTouch​Bar​Item
NSTracking​Area
NSTree​Controller
NSTree​Node
NSTypesetter
NSUser​Defaults​Controller
NSView
NSView​Animation
NSView​Controller
NSVisual​Effect​View
NSWindow
NSWindow​Controller
NSWorkspace
Protocols NSAccessibility
NSAccessibility​Button
NSAccessibility​Check​Box
NSAccessibility​Contains​Transient​UI
NSAccessibility​Element​Protocol
NSAccessibility​Group
NSAccessibility​Image
NSAccessibility​Layout​Area
NSAccessibility​Layout​Item
NSAccessibility​List
NSAccessibility​Navigable​Static​Text
NSAccessibility​Outline
NSAccessibility​Progress​Indicator
NSAccessibility​Radio​Button
NSAccessibility​Row
NSAccessibility​Slider
NSAccessibility​Static​Text
NSAccessibility​Stepper
NSAccessibility​Switch
NSAccessibility​Table
NSAlert​Delegate
NSAlignment​Feedback​Token
NSAnimatable​Property​Container
NSAnimation​Delegate
NSAppearance​Customization
NSApplication​Delegate
NSBrowser​Delegate
NSCandidate​List​Touch​Bar​Item​Delegate
NSChange​Spelling
NSCloud​Sharing​Service​DelegateNSCloud​Sharing​Validation
NSCollection​View​Data​Source
NSCollection​View​Delegate
NSCollection​View​Delegate​Flow​Layout
NSCollection​View​Element
NSCollection​View​Section​Header​View
NSColor​Picking​Custom
NSColor​Picking​Default
NSCombo​Box​Cell​Data​Source
NSCombo​Box​Data​Source
NSCombo​Box​Delegate
NSControl​Text​Editing​Delegate
NSDate​Picker​Cell​Delegate
NSDictionary​Controller​Key​Value​Pair
NSDock​Tile​Plug​In
NSDragging​Destination
NSDragging​Info
NSDragging​Source
NSDrawer​Delegate
NSEditor
NSEditor​Registration
NSFile​Promise​Provider​Delegate
NSFont​Panel​Validation
NSGesture​Recognizer​Delegate
NSGlyph​Storage
NSHaptic​Feedback​Performer
NSIgnore​Misspelled​Words
NSImage​Delegate
NSInput​Server​Mouse​TrackerNSInput​Service​Provider
NSKey​Value​Binding​Creation
NSLayer​Delegate​Contents​Scale​Updating
NSLayout​Manager​Delegate
NSMatrix​Delegate
NSMenu​Delegate
NSMenu​Validation
NSOpen​Save​Panel​Delegate
NSOutline​View​Data​Source
NSOutline​View​Delegate
NSPage​Controller​Delegate
NSPasteboard​Item​Data​Provider
NSPasteboard​Reading
NSPasteboard​Writing
NSPath​Cell​Delegate
NSPath​Control​Delegate
NSPlaceholders
NSPopover​Delegate
NSPrint​Panel​Accessorizing
NSRule​Editor​Delegate
NSScrubber​Data​Source
NSScrubber​Delegate
NSScrubber​Flow​Layout​Delegate
NSSearch​Field​Delegate
NSSegue​Performing
NSServices​Menu​Requestor
NSSharing​Service​Delegate
NSSharing​Service​Picker​Delegate
NSSharing​Service​Picker​Touch​Bar​Item​Delegate
NSSound​Delegate
NSSpeech​Recognizer​Delegate
NSSpeech​Synthesizer​Delegate
NSSplit​View​Delegate
NSSpring​Loading​Destination
NSStack​View​Delegate
NSTab​View​Delegate
NSTable​View​Data​Source
NSTable​View​Delegate
NSText​Attachment​Cell​Protocol
NSText​Attachment​Container
NSText​Delegate
NSText​Field​Delegate
NSText​Finder​Bar​Container
NSText​Finder​Client
NSText​Input
NSText​Input​Client
NSText​Layout​Orientation​Provider
NSText​Storage​Delegate
NSText​View​Delegate
NSToken​Field​Cell​Delegate
NSToken​Field​Delegate
NSTool​Tip​Owner
NSToolbar​Delegate
NSToolbar​Item​Validation
NSTouch​Bar​Delegate
NSTouch​Bar​Provider
NSUser​Interface​Item​Identification
NSUser​Interface​Item​Searching
NSUser​Interface​Validations
NSValidated​User​Interface​Item
NSView​Controller​Presentation​Animator
NSWindow​Delegate
NSWindow​Restoration
NSWindow​Scripting
Reference NSApple​Script App​Kit Additions
App​Kit Functions
App​Kit Data Types
App​Kit ConstantsApp​Kit Enumerations
Structures NSApplication​Activation​Options
NSApplication​Occlusion​State
NSApplication​Presentation​Options
NSAutoresizing​Mask​Options
NSBitmap​Format
NSCell​Hit​Result
NSCell​Style​Mask
NSCloud​Kit​Sharing​Service​Options
NSCollection​View​Scroll​Position
NSColor​Panel​Options
NSDate​Picker​Element​Flags
NSDrag​Operation
NSDragging​Item​Enumeration​Options
NSEvent​Button​Mask
NSEvent​Mask
NSEvent​Modifier​FlagsNSEvent​PhaseNSEvent​Swipe​Tracking​OptionsNSFont​Collection​OptionsNSFont​Collection​Visibility
NSFont​Trait​Mask
NSGradient​Drawing​Options
NSLayout​Format​Options
NSMedia​Library
NSMenu​Properties
NSPDFPanel​Options
NSPasteboard​Contents​Options
NSPasteboard​Reading​Options
NSPasteboard​Writing​Options
NSPrint​Panel​Options
NSRemote​Notification​Type
NSSlider​Accessory​Width
NSSpring​Loading​Options
NSStatus​Item​Behavior
NSString​Drawing​Options
NSTable​Column​Resizing​Options
NSTable​View​Animation​Options
NSTable​View​Grid​Line​Style
NSText​List​Options
NSText​Storage​Edit​Actions
NSTouch​Bar​Customization​IdentifierNSTouch​Bar​Item​IdentifierNSTouch​Bar​Item​Priority
NSTouch​Phase
NSTouch​Type​Mask
NSTracking​Area​Options
NSTypesetter​Control​Character​Action
NSView​Controller​Transition​Options
NSWindow​Collection​Behavior
NSWindow​List​Options
NSWindow​Occlusion​State
NSWindow​Style​Mask
NSWorkspace​Icon​Creation​Options
NSWorkspace​Launch​Options
Extended Types CIColor
CIImage
Cocoa​Error
Cocoa​Error.Code
Index​Path
NSAffine​Transform
NSApple​Script
NSAttributed​String
Bundle
NSException​Name
File​Wrapper
NSIndex​Path
NSItem​Provider
NSMutable​Attributed​String
NSNotification.Name
NSObject
Run​Loop​Mode
NSSet
NSString
NSURL
URLResource​Values

转载请注明:天狐博客 » AppKit Framework Reference

微信 OR 支付宝 扫描二维码
为天狐 打赏
非常感谢你的支持,哥会继续努力!
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址