Apple Watch Development (iii)--watchkit introduction and watch adaptation, layout

Source: Internet
Author: User

Tagged with: iOS Apple Watch watch development WatchKit watch adaptation

The previous article briefly describes the process of creating an Apple Watch development project, so what's the use of a newly generated file? How does an old project fit with Apple Watch? Below I will briefly introduce the role of the file in the WatchKit and watch project, and its layout features.

An old project to match Apple Watch

Can I add Apple Watch to a regular old project? What to pay attention to? Some people directly in the old project, according to the previous article to add an Apple Watch target, but a compilation found an error, the error is as follows:

Error:watchkit apps must has a deployment target equal to IOS 8.2 (was 8.3).

See the error, as the name implies, we go to modify the Watch app corresponding to the deployment target version on the line, as follows:


Ii. Introduction of the project

After we created the project in the previous article and found it to automatically create a few storyboard, check Interface.storyboard, on the right will find there are four kinds of storyboard, that is, we said in the first article of the three ways of interaction or interface type: Watch app, glance, notification (static, dynamic)


And we go back to the Extension Code section, Check the InterfaceController.h file, we found that there is no previous Uikit framework, but WatchKit, before the UIView and the like in this is not good, but a set of new layout; similar to Uiviewcontroller, there are controllers here, but it Inherited from Wkinterfacecontroller, it is a subclass of NSObject, and Uiviewcontroller has no relationship:


This also confirms the linkage between Apple Watch and iphone that we said in our first article:


Third, watch news alert

In addition we click on the Pushnotificationpayload.apns file, will find a JSON string, inside the key keyword, I believe you are not unfamiliar, yes this is the configuration of the notification interface configuration file, there is a message prompt content and button title, etc.;


In addition we look at the notification type of interface, divided into static and dynamic, static is in accordance with the content of our configuration prompts, and the dynamic is based on the app push message display:


Then the notification interface works as follows:


Iv. introduction of WatchKit

If we check the interfacecontroller.m file, we will find that the auto-generated method is similar to our previous uiviewcontroller, and can be regarded as Uiviewcontroller init,viewdidload, respectively. Viewwillappear, Viewdidunload:


They also operate in similar principles:



So what are the general classes in WatchKit? In the official documentation we can see the following classes and their descriptions:



WatchKit has just emerged, there are many needs to be perfected and expanded, currently in watch development in the use of a few components, mainly the following components:


V. How watch is laid out

The following is a brief introduction to the layout of the Watch app components, their layout is similar to the relative layout of Android or Web page, divided into: left and right, upper and lower layout;


It is useless to force the position of the component manually, and the position must be set on the right:


Because the Watch app's interface layout is storyboard layout, some components and code are associated with the previous use of xib, but these controls are generated in a different way than before, such as the method of the button is without parameters, the following common components generated by the method:


(Reproduced Please specify: http://blog.csdn.net/yujianxiang666)

Apple Watch Development (iii)--watchkit introduction and watch adaptation, layout

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.