Apple Watch Development (iii) -- Introduction to WatchKit and adaptation and layout of Watch, -- watchkitwatch

Source: Internet
Author: User

Apple Watch Development (iii) -- Introduction to WatchKit and adaptation and layout of Watch, -- watchkitwatch

 

The previous article briefly introduced the process of creating a project developed by Apple Watch. What is the use of newly generated files? How can old projects adapt to Apple Watch? Next I will briefly introduce the functions and layout features of the files in the WatchKit and Watch projects.

 

I. Adaptation of old projects to Apple Watch

Can I add an Apple Watch to an ordinary old project? What do you need to pay attention? Some people add an Apple Watch Target directly in the old project as described in the previous article. However, an error occurs during compilation and the following error is reported:

Error: WatchKit apps must have a deployment target equal to iOS 8.2 (was 8.3 ).

If you see an error, as the name suggests, you can modify the deployment target version corresponding to the Watch app. For details, see:


 

Ii. Project Overview

In the previous article, after creating a project, we found that it automatically created several storyboards and selected Interface. storyboard. There are four types of storyboard on the right, that is, the three interaction methods or interface types described in the first article: Watch app, glance, and notification (static and dynamic)


 

Return to the Extension code section and select InterfaceController. h file, we found that there is no previous UIKit framework here, But WatchKit, the previous UIView and so on are not easy to make, but a new layout method; similar to UIViewController, there is also a controller here, But it inherits from WKInterfaceController, which is a subclass of NSObject and has no relationship with UIViewController:


This also confirms the linkage binding between Apple Watch and iPhone as mentioned in the first article:


 

3. Watch message reminder

In addition, click PushNotificationPayload. the apns file will be found to be a json string with the key keyword. I believe you are not new to it. That's right. This is the configuration file for configuring the notification interface, including the message content and the button title;


In addition, let's take a look at the notification interface, which is static and dynamic. The static interface is prompted according to the content we configured, and the dynamic interface is displayed based on the message pushed by the app:


The interface running principle of notification is as follows:


 

4. Introduction to WatchKit

When we select the InterfaceController. m file, we will find that the automatically generated method is similar to our previous UIViewController, which can be viewed as the init, viewDidLoad, viewWillAppear, and viewDidUnload of UIViewController:


Their operating principles are similar:



What are the classes in WatchKit? In the official document, we can see the following classes and their introduction:



WatchKit has just emerged and needs to be improved and expanded. Currently, there are not many components used in Watch development, mainly including the following components:


 

5. Watch Layout

The following briefly introduces the layout features of the Watch app components. Their layout is similar to the relative layout of Android or web pages, which can be divided into: Left, right, top, and bottom;


It is useless to forcibly drag the component. You must set the position on the right side:


Because the interface layout of the Watch app is storyboard layout, the association between some components and code is the same as that of the previous xib, but these controls are generated in a different way than before, for example, the button method does not contain parameters. The following common component generation methods are as follows:


 

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

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.