pdf iOS开发 精通iOS开发英文原版

所需积分/C币:4 2017-11-04 16:19:07 20.33MB PDF

Contents at a Glance About the authors About the technical reviewer ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ XXII Acknowledgments XXv Introduction Chapter 1: Welcome to the Jungle. ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ Chapter 2: Appeasing the Tiki Gods. 13 Chapter 3: Handling basic Interaction mammmammmammmmmammmma. 45 Chapter 4: More User Interface Fun ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■a■ Chapter 5: Autorotation and Autosizing na119 Chapter 6: Multiview Applications ammmmmmtalr ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 141 Chapter 7: Tab bars and pickers mmmmmmmmmmmammmmmmmmmmmma 171 Chapter 8: Introduction to Table views u215 Chapter 9: Navigation Controllers and Table views. 263 Chapter 10: Collection View ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■■■■■■■■■■■■ 299 Chapter 11: iPad considerations mmmmmammmmmmamaa maa 313 Chapter 12: Application Settings and User Defaults.mea 343 Chapter 13: Basic Data Persistence ummaammmmmmaammmamaammmmmaa 379 Contents at a glance Chapter 14: Documents and icloud ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 425 Chapter 15: Grand Central Dispatch, Background Processing, and You naamanmma 455 Chapter 16: Drawing with Core Graphics mEmE 89 Chapter17: Getting Started with Sprite Kit,,,,,…,,…,,,,…,…,,519 Chapter 18: Taps Touches, and gestures a ■■■■■■■■■■■■■■a 563 Chapter 19: Where Am I? Finding Your Way with Core Location and Map Kit. 595 Chapter 20: Whee! Gyro and Accelerometer ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 613 Chapter 21: The Camera and Photo library nmamamammmamaanam 641 Chapter 22: Application Localization aaammmaamaaaaaama IIRaIamImmaI 653 Index ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 675 Introduction This book is enormous. If you are reading a paper copy, you're well aware of this, but if you've got a digital copy, you might not understand the size of this thing. I mean, it's larger than most bibles Ive seen. Not that I'm an expert on bibles or anything, but you know: they're big, fat books. If you asked Is Beginning iOS 7 Development bigger than a breadbox? " I'd have to say,"Almost. And yet, this book is made of smaller pieces, portioned out so that you should be able to tackle the contents of any single chapter in a delightful afternoon, learning things about ios development that you probably never imagined. When I say"tackle, I don't mean just read each chapter. I mean you nee to actually sit down in front of a mac and work your way through it. Building all the example apps as you go through each chapter will help imprint all the usage patterns and concepts into your brain in a way that reading alone could never do. If you work your way through this book, you will come away with a great understanding of the foundations of ioS app development, and you will be more than ready to build ios apps all on your own Many years ago, I met the late Torfrid Olsson, a Swedish sculptor from a rural area of northern Sweden. I expressed to him some envy and admiration about one aspect of his life, and his reply stuck with me: Ah, that's just something you've read about in books. You have your own life that is uniquely yours. What makes you think that it's missing anything? My hope is that you don't let the knowledge contained in these pages just be something you read in a book. Read it, of course, but also work through it, understand it, and wrestle it to the ground if you must. make it yours Jack Nutting Stockholm 2014 Chapter Welcome to the jungle So, you want to write iPhone, iPod touch, and iPad applications? Well, we can't say that we blame you. iOS, the core software of all of these devices, is an exciting platform that has been seeing explosive growth since it first came out in 2007. The rise of the mobile software platform means that people are using software everywhere they go With the release of ioS 7, Xcode 5, and the latest incarnation of the ios software development kit (SDK), things have only gotten better and more interesting What this book is This book is a guide to help you get started down the path to creating your own ios applications Our goal is to get you past the initial difficulties, to help you understand the way iOS applications work and how they are built As you work your way through this book, you will create a number of small applications, each designed to highlight specific ioS features and to show you how to control or interact with those features. If you combine the foundation you'll gain through this book with your own creativity and determination, and then add in the extensive and well-written documentation provided by apple you'll have everything you need to build your own professional iPhone and iPad applications Tip Jack, Dave, Jeff, and Fredrik have set up a forum for this book It's a great place to meet like-minded folks, get your questions answered, and even answer other people's questions the forum is at http://forum.learncocoa.orgBesuretocheckitout! CHAPTER 1: Welcome to the jungle What you need Before you can begin writing software for iOS, you'll need a few items. For starters, you'll need an Intel-based Macintosh, running Mountain Lion(OS X 10.8), Mavericks(OS X 10. 9 )or later. Any recent Intel-based Macintosh computer-laptop or desktop-should work just fine To get access to the latest and greatest from Apple, you' ll also really need to sign up to become a registered ios developer To create your developer account, just navigate to http://developer.applecom/ios/.ThatwillbringyoutoapagesimilartotheoneshowninFigure1-1 iOS Dev Center- Apple developer 口Nws, NN- WholeNote- bodies.WholeNote- r goodies”第 XRAY Keep It! e (p MRI Fun, Programmin/O IcA++ Apple Inc.a develeper. apple. cam/deventer/ias/index.action Developer Technologies Resources Programs Support Member Center(SEarch Developer iOS Dev Center as Dey Center Mac Dev Center Safari Dev Center HL Guest Register Log In Access additional resources in the ioS Dev Center. sign in Sign in with the apple id you used to register as an apple developer, or register for free today Development Resources iOS Developer Program Documentation and videos Featured Content App Revlew Guidelines Prepare your apps for the iOS Developer Library Create Apps for iOs 7 approval process. View the latest documentation and sample a ios 7 Design Resources Learn more p code for ios 7 os 7 UI Transition Guide Getting Started Sample Code Xcode Continuous Integration Guide App Store Resource Center e Guides e Technical Notes Reference e Technical o&As Start Developing iOS Apps Today Get information on distributing your app on e Release notes a App Distribution Guide the App store. Sign in b a Developing Apps for iPad OS App Programming Guide Development videos News and Announcements iOS Development WwDC Videos iOS Human Interface Guidelines Stay up to date with the Programming with Objective-C latest Apple and announcements Downloads Check the status of your pending Xcode 5 iOS Developer Program Download the complete developer toolset for building Mac, iPhone, and iPad apps, including the enrollment Xcode iDE, performance analysis tools, iOS Simulator and the latest os x and iOs SDKs. Sign in b Figure 1-1. Apple's iOs Dev center website CHAPTER 1: Welcome to the Jungle First, click Log in. You'l be prompted for your Apple ID If you don't have an Apple ID, click Join now, create such an ID, and then log in Once you are logged in, you'll be taken to the main ios development page. You'll find links to a wealth of documentation, videos, sample code, and the like -all dedicated to teaching you the finer points of iOS application development The most important tool you' ll be using to develop iOS applications is called Xcode Xcode is Apples integrated development environment(IDE). Xcode includes tools for creating and debugging source code, compiling applications, and performance tuning the applications you've written You can download Xcode from the Mac App Store, which you can access from your Mac's Apple menu SDK VERSIONS AND SOURCE CODE FOR THE EXAMPLES As the versions of the SDK and Xcode evolve the mechanism for downloading them will also change for the past few years, Apple has been publishing the current" stable "version of Xcode and the ioS SDK on the Mac App store, while simultaneously often providing developers the ability to download preview versions of upcoming releases from its developer site. Bottom line you want to download the latest released(non-beta) version of Xcode and the iOS SDK, so use the Mac App store This book has been written to work with the latest version of the SDK. In some places, we have chosen to use nev functions or methods introduced with ioS 7 that may prove incompatible with earlier versions of the SDK. We' ll be sure to point those situations out as they arise in this book Besuretodownloadthelatestandgreatestsourcecodearchivesfromhttp://learncocoa.orgorfromthebooks forumathttp://forum.learncocoa.orgWe'llupdatethecodeasnewversionsoftheSdkarereleasedsobesure to check the site periodically Developer options The free Xcode download includes a simulator that will allow you to build and run iphone and iPad apps on your Mac. This is perfect for learning how to program for iOS. However, the simulator does not support many hardware-dependent features, such as the accelerometer and camera. Also, the free option will not allow you to install your applications onto a real iPhone or other device, and it does not give you the ability to distribute your applications on Apple's App Store. For those capabilities, you'll need to sign up for one of the other options, which arent free The Standard program costs $99/year. It provides a host of development tools and resources, technical support, distribution of your application via apple's App Store, and, most importantly, the ability to test and debug your code on an iOS device, rather than just in the simulator. The Enterprise program costs $299/year. It is designed for companies developing proprietary, in-house iOS applications Formoredetailsontheseprogramsvisithttp://developer.applecom/programs/iosand http://developer.apple.com/programs/ios/enterprisetocomparethetwo CHAPTER 1: Welcome to the jungle Because iOS supports an always-connected mobile device that uses other companies'wireless infrastructure, Apple has needed to place far more restrictions on ios developers than it ever has on Mac developers(who are able -at the moment, anyway-to write and distribute programs with absolutely no oversight or approval from Apple). Even though the iPod touch and the Wi-Fi- only versions of the iPad don't use anyone else's infrastructure, they 're still subject to these same restrictions Apple has not added restrictions to be mean, but rather as an attempt to minimize the chances of malicious or poorly written programs being distributed that could degrade performance on the shared network. Developing for ios may appear to present a lot of hoops to jump through, but Apple has expended quite an effort to make the process as painless as possible. and also consider that $99 is still much less expensive than buying, for example, Visual Studio, which is Microsoft's software development IDE This may seem obvious, but you' ll also need an iPhone, iPod touch, or iPad. While much of your code can be tested using the iOS simulator, not all programs can be. And even those that can run on the simulator really need to be thoroughly tested on an actual device before you ever consider releasing your application to the public Note If you are going to sign up for the standard or Enterprise program, you should do it right now. The approval process can take a while, and you'lI need that approval to be able to run your applications on an actual device Don' t worry, though, because all the projects in the first several chapters and the majority of the applications in this book will run just fine on the iOS simulator. What you need to know This book assumes that you already have some programming knowledge. It assumes that you understand the fundamentals of programming in general and object-oriented programming in particular (you know what classes, objects, loops, and variables are, for example). It also assumes that you are familiar with the objective-C programming language. Cocoa Touch, the part of the SDK that you will be working with through most of this book, uses the latest version of objective-C, which contains several new features not present in earlier versions. But don't worry if you're not familiar with the more recent additions to the Objective-C language. We highlight any of the new language features we take advantage of, and explain how they work and why we are using them you should also be familiar with iOS itself, as a user. Just as you would with any platform for which you wanted to write an application, get to know the nuances and quirks of the iPhone, iPad, or iPod touch. Take the time to get familiar with the iOS interface and with the way Apple's iPhone and/or iPad applications look and feel CHAPTER 1: Welcome to the Jungle NEW TO OBJECTIVE-C? If you have not programmed in Objective-C before, here are a few resources to help you get started Learn Objective-C on the Mac: For os X and ioS (2nd edition, Apress, 2012): this is an excellent and approachable introduction to Objective-C by Mac-programming experts Scott Knaster, Wagar Malik,andMarkDalrymple.Youcanfindmoreinformationathttp://www.apress.com/book/ View/9781430241881 Programming with Objective-C. this is apple's introduction to the language. You can find more informationathttps://developer.applecom/library/mac/documentation/cocoa/ conceptual/ProgrammingwithobjectiveC What's Different About Coding for iOS? If you have never programmed in Cocoa or its predecessors NeXTstEP or Open Step you may find Cocoa Touch -the application framework you'll be using to write iOS applications-a little alien. It has some fundamental differences from other common application frameworks, such as those used when building. NET or Java applications. Don't worry too much if you feel a little lost at first. Just keep plugging away at the exercises, and it will all start to fall into place after a while If you have written programs using Cocoa or NeXTSTEP, a lot in the ios sDK will be familiar to you. a great many classes are unchanged from the versions that are used to develop for oS X Even those that are different tend to follow the same basic principles and similar design patterns However several differences exist between Cocoa and Cocoa Touch Regardless of your background, you need to keep in mind some key differences between iOs development and desktop application development. These differences are discussed in the following sections Only One Active Application On iOS, only one application can be active and displayed on the screen at any given time. Since IOS 4, applications have been able to run in the background after the user presses the"home button, but even that is limited to a narrow set of situations and you must code for it, specifically When your application isn 't active or running in the background, it doesn t receive any attention Whatsoever from the cpu, which will wreak havoc with open network connections and the like iOs allows background processing, but making your apps play nicely in this situation will require some effort on your part Only One Window Desktop and laptop operating systems allow many running programs to coexist, each with the ability to create and control multiple windows. However, ios gives your application just one"window" to work with. All of your applications interaction with the user takes place inside this one window, and its size is fixed at the size of the screen


关注 私信 TA的资源