iOS框架总览

Survey the Major Frameworks

A framework is a directory that includes a shared library, header files to access the code stored in that library, and other resources such as image and sound files. A shared library defines functions and methods that apps can call.

iOS provides many frameworks that you can use in app development. To use a framework, add it to your project so your app can link to it. Most apps link to the Foundation, UIKit, and Core Graphics frameworks. Depending on which template you choose for your app, other frameworks might also be included. You can always add additional frameworks to your project if the core set of frameworks does not meet your app’s requirements.

bullet
To look at the frameworks included in HelloWorld.xcodeproj . . .
  1. Open the HelloWorld.xcodeproj project in Xcode (if it’s not already open). You created this project earlier in theYour First iOS App tutorial.

  2. Open the Frameworks folder in the project navigator by clicking the disclosure triangle next to it.

    You should see UIKit.frameworkFoundation.framework, and CoreGraphics.framework.

  3. You can view the header files in a framework by clicking the disclosure triangle next to the framework and then clicking the disclosure triangle next to the Headers folder.

Each framework belongs to a layer of the iOS system. Each layer builds on the ones below it. Use higher-level frameworks instead of lower-level frameworks whenever possible. Higher-level frameworks provide object-oriented abstractions for lower-level constructs.

image: ../Art/framework_layer.png

iOS Apps Are Based on the Foundation and UIKit Frameworks

When you begin programming, you mainly use the Foundation and UIKit frameworks because they cover most of your app development needs.

 

The Foundation Framework Provides Basic System Services for All Apps

Your apps, as well as UIKit and other frameworks, are built on the Foundation framework infrastructure. The Foundation framework provides Objective-C wrappers for many of the features in the Core Foundation framework (which is C-based).

Use Foundation to:

  • Create and manage collections such as arrays and dictionaries.

  • Access images and other resources stored in your app.

  • Create and manage strings.

  • Post and observe notifications.

  • Create date and time objects.

  • Automatically discover devices on IP networks.

  • Manipulate URL streams.

  • Perform code asynchronously.

You already used the Foundation framework in Your First iOS App. For example, you used an instance of the NSStringclass to store the user’s input in userName. You also used the Foundation instance method initWithFormat: to create the greeting string.

 

The UIKit Framework Provides Classes to Create a Touch-Based User Interface

All iOS apps are based on UIKit—you can’t ship an app without this framework. UIKit provides the infrastructure for drawing to the screen, handling events, and creating common user-interface elements. UIKit also organizes a complex app by managing the content that is displayed onscreen.

Use UIKit to:

  • Construct and manage your user interface.

  • Handle touch and motion-based events.

  • Present text and web content.

  • Optimize your app for multitasking.

  • Create custom user-interface elements.

In Your First iOS App Tutorial, you used UIKit. When you examined how an app starts up, you saw that theUIApplicationMain function creates an instance of the UIApplication class, which handles incoming user events. You implemented the UITextFieldDelegate protocol in order to dismiss the keyboard when the user taps the Done key. In fact, you used UIKit to create your entire interface with the UITextFieldUILabel, and UIButton classes.

 

Other Important Frameworks You Should Know About

The Core Data, Core Graphics, Core Animation, and OpenGL ES frameworks are advanced technologies. Although these frameworks are important for app development, they require time to learn and master.

 

The Core Data Framework Manages the Data Model of an App

Core Data provides object-graph management. With Core Data, you create model objects, known as managed objects. You manage relationships between those objects and make changes to the data through the framework. Core Data takes advantage of the built-in SQlite technology to store and manage data efficiently.

Use Core Data to:

  • Save and retrieve objects from storage.

  • Support basic undo/redo.

  • Validate property values automatically.

  • Filter, group, and organize data in memory.

  • Manage results in a table view with [NSFetchedResultsController].

  • Support document-based applications.

 

The Core Graphics Framework Helps You Create Graphics

High-quality graphics are an important part of all iOS applications. The simplest and most efficient way to create graphics in iOS is to use prerendered images with the standard views and controls of the UIKit framework and let iOS do the drawing. When you need to create complex graphics, Core Graphics provides a low-level graphics library to help you. Core Graphics, also known as Quartz, handles native 2D vector- and image-based rendering.

Use Core Graphics to:

  • Make path-based drawings.

  • Use anti-aliased rendering.

  • Add gradients, images, and colors.

  • Use coordinate-space transformations.

  • Create, display, and parse PDF documents.

 

Core Animation Allows You to Make Advanced Animations and Visual Effects

UIKit provides animations that are built on top of the Core Animation technology. If you need advanced animations beyond the capabilities of UIKit, you can use Core Animation directly. The Core Animation interfaces are contained in the Quartz Core framework. With Core Animation, you create a hierarchy of layer objects that you manipulate, rotate, scale, transform, and so forth. By using Core Animation’s familiar view-like abstraction, you can create dynamic user interfaces without having to use low-level graphics APIs like OpenGL ES.

Use Core Animation to:

  • Create custom animations.

  • Add timing functions to graphics.

  • Support key frame animation.

  • Specify graphical layout constraints.

  • Group multiple-layer changes into an atomic update.

 

The OpenGL ES Framework Provides Tools for 2D and 3D Drawing

OpenGL ES supports basic 2D and 3D drawing. Apple’s implementation of the OpenGL ES standard works closely with the device hardware to provide high frame rates for full-screen game-style applications.

Use OpenGL ES to:

  • Create 2D and 3D graphics.

  • Make more complex graphics such as data visualization, flight simulation, or video games.

  • Access underlying graphics hardware.

 

Add Other Frameworks to Your Project as Needed

There are many more frameworks you can use in your app. When you decide that you need to use a framework that is not already included, add the framework to your project so your app can link to it.

image: ../Art/project_editor.jpg

bullet
To link the HelloWorld.xcodeproj to another framework . . .
  1. Open the HelloWorld.xcodeproj project in Xcode (if it’s not already open).

  2. Click the HelloWorld project in the project navigator to show the project editor.

  3. Specify HelloWorld as the target to which you want to add a framework by clicking HelloWorld in the Targets list.

  4. Click Build Phases at the top of the project editor.

  5. Open the Link Binary With Libraries section by clicking the disclosure triangle.

  6. Click the Add (+) button to add a framework.

  7. Select a framework from the list and click Add.

For a complete list of the frameworks, or to learn more about them, see the iOS Technology Overview.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值