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

How can a brand create a hit product?

01 Content drives traffic The concept of "co...

Tips for attractive job ads!

As we all know, a job advertisement consists of t...

Top 10 Tips to Improve WeChat Official Account Activity

Today, Feng Chao, editor of Jimifeng Technology, ...

White Paper on Mobile Advertising Traffic Observation in the First Half of 2021

In the first half of 2021, many new opportunities...

Honda's Japanese factory shut down for one day due to ransomware attack

According to Reuters, Honda Motor said on June 21...

How do companies operate Douyin? Just use these 5 tricks!

Nowadays, “two Weibo and one Douyin” have become ...

Summary of new media marketing hot spots and wonderful cases in May

Brand promotion can greatly increase exposure by ...

Community Operation SOP Methodology

From my own perspective, I sorted out my understa...

Huang Yongsheng's resume: website promotion and marketing skills

Website promotion and marketing of pharmacies 1. ...