Summary of WatchKit view transition control

Summary of WatchKit view transition control

[[134793]]

For WatchKit App, you can create multiple InterfaceControllers in Storyboard and draw view conversion connections intuitively like in iOS applications. Of course, we can also implement corresponding view switching and jumping through view controller code.

In short, there are three forms of view conversion connections:

1. Push/Pop - Provides stack-based view control in Hierarchical form. Hierarchical means hierarchical view architecture. The effect is similar to the Navigation interface in iOS applications. It is mainly used for view conversion of navigation classes. First, there must be a root view controller. When the next level view is pushed into the stack and popped out by triggering dragging in Storyboard or using pushControllerWithNames: code, a <left arrow will be added in front of the title bar. Clicking it will return to the previous level view. You can also execute popController() code, and you can use popToRootController() to directly return to the root view.

2.Present - Similar to the Push method, it will jump to a Modal view. The difference is that the controller of the current view will be released and the didDeactivate method will be executed, but we can still click the title bar in the modal view or call the dismissController() method in the view controller code to reactivate the previous view.

3.Next page - Paginated view mode, multiple views are arranged horizontally and side by side. Swipe left or right to switch, with small dots at the bottom to mark. Now many iOS apps have this paginated navigation when they start, which is used to prompt operation methods or new functions. In Storyboard, hold down control and drag from view A to view B and select next page to establish this relationship.

For details, please refer to the article "WatchKit Programming Guide: WatchKit Apps--Interface Navigation":

The following is a summary of some common problems and their solutions:

1.Q: When the main controller is a paging view, the hierarchical view stack cannot be pushed; when the main controller is a hierarchical view, the paging view cannot be pushed.

A: Page-based and Stack modes are mutually exclusive, so you must use a modal method to switch. When the main controller is a paging view, you can use the presentControllerWithName: method to correctly pop up a hierarchical view stack. When the main controller is a hierarchical view, you can use the

  1. presentControllerWithName:conext:

Method, and pop up a paging view consisting of multiple pages, you need to use

  1. presentControllerWithNames:contexts:

method.

2.Q: How to pass parameters between views?

A: Use the context parameter to encapsulate the parameter object. If you need to pass the view controller delegate in push mode, you can refer to the article "WatchKit's Delegate and Context" that I translated before.

3. Q: I defined a context menu for ForceTouch, but when I switched views and activated the context menu and clicked it, an error message appeared saying that the view pointer was lost.

A: Because you defined the context menu in awakeWithContext: in your code, and then popped it up modally, so the original view is destroyed after switching views and the menu content code cannot be called correctly. The solution is: I. Use push to switch views, so that the main view is stored in the view stack and the object is not destroyed; II. Still use modal to switch views, but put the context menu definition code in willActivate() function, so that the menu definition will be reloaded and will not be invalid.

<<:  Graduation season: Cocos, a post-90s developer, talks about how to enter the industry and how to make progress

>>:  Programmers are not bricklayers, they are writers

Recommend

JD spare parts library domestic sales channel Baidu cloud download

JD Spare Parts Domestic Sales Channel Introductio...

Gartner: Global AI chip revenue will grow 33% in 2024

According to Gartner's latest forecast, globa...

About Tint Color Properties

Tint Color After iOS 7, UIView added a new tintCo...

Why is brand advertising ineffective?

From selling goods to selling brands; from sellin...

Useful Information | How to plan a public account operation plan?

I'm currently working on an overall operation...

How can advertising creatives be designed to stimulate user interaction?

With the rapid development of the mobile gaming i...

Play with Android nested scrolling

In the process of Android UI development, we ofte...

Feed Little Prince FEED flow practical online teaching course

Feed Little Prince FEED flow practical online tea...

How to analyze retention data and reduce user churn?

As we enter the second half of the Internet era, ...

TSMC will launch 12nm process, leaving GlobalFoundries in the dust

At the beginning of this year, the poor yield rat...

A new choice for a 150,000-class family SUV? Test drive Kia EV5

NetEase Auto reported on December 2 that the fami...