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

Source: Internet
Author: User
Tags new set

The previous article briefly describes the process of creating a project that was developed by Apple Watch, so what is the use of the newly generated file? How does the old project fit with the Apple Watch? Below I will briefly introduce the WatchKit and watch project in the file role, and its layout characteristics.

first, the old project suitable with Apple Watch

Ordinary old project can add Apple Watch. Need to pay attention to what. Some people add a target for Apple Watch directly in the old project, as described in the previous article, but a compilation found an error, and the error is as follows:

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

See the error, as the name suggests, we go to modify the next watch app corresponding deployment target version on the line, the following figure:


Ii. Introduction of the project

After we created the project in the previous article, we found that it had created a few storyboard, selected Interface.storyboard, and found there are four kinds of storyboard on the right, that is, the three kinds of interaction or interface types mentioned in our first article: 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 so on in this is not good, but a new set of layout; similar to Uiviewcontroller, there are controllers, but it Inherited from Wkinterfacecontroller, which is a subclass of NSObject, has nothing to do with Uiviewcontroller:


This confirms what we said in the first installment of the Apple Watch and iphone binding relationship:


third, watch message reminder

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


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


Then the notification interface operation principle is:


Iv. Brief introduction of WatchKit

We select the interfacecontroller.m file, we will find that the automatic generation of methods and our previous Uiviewcontroller similar, such as the figure can be seen as Uiviewcontroller init,viewdidload, Viewwillappear, Viewdidunload:


They run the same principle:



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



WatchKit just emerged, there are many need to improve and expand, currently in the watch development of the components used, mainly the following components:


Five, the Watch layout way

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


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


Because the interface layout of Watch app is storyboard layout, some components and code are associated with the same as before Xib, but these controls generate a different method than before, such as the button method is not with parameters, the following common components generated methods:


(Reprint please specify: http://blog.csdn.net/yujianxiang666)

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.