Disclosure of Invention
Based on this, it is necessary to provide a view switching method, device, computer equipment and storage medium for solving the technical problems of memory explosion caused by creating multiple controllers in one interface and causing application program operation to be blocked in the conventional technology.
A method of view switching, the method comprising:
monitoring a first view switching operation occurring in an application interface;
if the first view switching operation is monitored, searching a first controller waiting for reuse from a reuse view container, and placing the searched first controller into a visible view container;
acquiring data to be displayed corresponding to the first view switching operation through a first controller in the visible view container;
and displaying the corresponding target view in the application interface according to the acquired data to be displayed.
In one embodiment, the searching the first controller waiting for reuse from the reuse view container and placing the first controller in the visible view container includes:
judging whether the reuse view container has a first controller waiting for reuse or not;
if the first controller waiting for reuse exists, the first controller waiting for reuse is searched from the reuse view container, and the searched first controller is placed in the visible view container.
In one embodiment, after the determining whether the reuse view container has a first controller waiting for reuse, the method further comprises:
if the first controller waiting for reuse does not exist, a second controller is created and placed in the visible view container;
and acquiring data to be displayed corresponding to the first view switching operation through a second controller in the visible view container.
In one embodiment, after the first controller to be found is placed in the visual view container, the method further comprises:
and deleting the searched first controller waiting for reuse from the reuse view container.
In one embodiment, after the corresponding target view is displayed in the application interface according to the acquired data to be displayed, the method further includes:
monitoring a second view switching operation occurring in the application interface;
judging whether the target view partially appears in the application interface;
if the second view switching operation is monitored and the target view portion appears in the application interface, the first controller is kept in the visible view container.
In one embodiment, the method further comprises:
and if the second view switching operation is monitored and the target view disappears in the application interface, deleting the first controller from the visible view container.
In one embodiment, the method further comprises:
the first controller is replaced in the reuse view container while the first controller is deleted from the visual view container.
A view switching device, the device comprising:
the switching operation monitoring module is used for monitoring a first view switching operation occurring in the application interface;
the controller searching module is used for searching a first controller waiting for reuse from the reuse view container if the first view switching operation is monitored, and placing the searched first controller into the visible view container;
the display data acquisition module is used for acquiring data to be displayed corresponding to the first view switching operation through a first controller in the visible view container;
and the target view display module is used for displaying the corresponding target view in the application interface according to the acquired data to be displayed.
A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the method of any of the embodiments described above when the computer program is executed.
A computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the method described in any of the embodiments above.
The view switching method, the device, the computer equipment and the storage medium are used for monitoring the first view switching operation in the application interface; if the first view switching operation is monitored, searching a first controller waiting for reuse from a reuse view container, and placing the searched first controller into a visible view container; acquiring data to be displayed corresponding to the first view switching operation through a first controller in the visible view container; and displaying the corresponding target view in the application interface according to the acquired data to be displayed. By creating the reuse view container and repeatedly utilizing the controllers in the reuse view container to display, the memory explosion caused by creating a plurality of controllers in the traditional technology is avoided, and the technical problem of the application program operation blocking is solved.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
The application provides a view switching method which can be applied to an application environment shown in fig. 1. The data interaction between the terminal 110 and the server 120 is performed through the network, and the data interaction method between the terminal 110 and the server 120 is not limited in the present application. The terminal 110 is provided with an application program and displays an interface of the application program, and multiple views are required to be displayed in the interface, and the multiple views respectively correspond to corresponding controllers. The terminal 110 monitors a first view switching operation occurring in the application interface; if the first view switching operation is monitored, searching a first controller waiting for reuse from the reuse view container, and placing the searched first controller into the visible view container. The terminal 110 obtains, by the first controller in the visible view container, data to be displayed corresponding to the first view switching operation; and displaying the corresponding target view in the application interface according to the acquired data to be displayed. The terminal 110 may obtain the data to be displayed from the local cache, or may obtain the data to be displayed from the server 120. Specifically, the first view switching operation terminal 110 initiates a view switching request to the server 120, the server 120 receives the view switching request, the view switching request carries display requirement information corresponding to the first view switching operation, and the first controller server 120 in the visible view container returns data to be displayed corresponding to the first view switching operation to the terminal 110 according to the display requirement information, where the terminal 110 may be, but not limited to, various personal computers, notebook computers, smartphones, tablet computers and portable wearable devices, and the server 120 may be implemented by an independent server or a server cluster formed by a plurality of servers.
In one embodiment, as shown in fig. 2, a view switching method is provided, and the method is applied to the terminal in fig. 1 for illustration, and includes the following steps:
s210, monitoring a first view switching operation in the application interface.
Wherein the running application program needs to display multiple views in the current application interface. The first view switching operation is an operation triggered by a view that the user desires to be presented in the application interface and is not currently displayed. The first view switching operation may be an operation of triggering a corresponding button in the application interface, or may be a triggering operation such as a left-right sliding or a up-down sliding sent on the application interface. Specifically, whether a trigger operation occurs in the application interface is monitored, if the trigger operation occurs in the application interface, whether the trigger operation is a first view switching operation or not is judged, namely, the first view switching operation occurring in the application interface is monitored.
S220, if the first view switching operation is monitored, searching a first controller waiting for reuse from the reuse view container, and placing the searched first controller into the visible view container.
The reuse view container refers to a view container for accommodating a controller waiting for reuse, and a view corresponding to the controller in the reuse view container is not currently shown in the application interface. And controlling the target view expected to be displayed in the application interface by the user through the first controller, and acquiring data corresponding to the target view from the server or the local cache. The visual view container refers to a view container for accommodating a controller corresponding to a current visual view in the application interface.
Specifically, the running application needs to display multiple views in the current application interface, and does not create a corresponding multiple controllers. But rather attempts to find a first controller waiting for reuse from a previously created reuse view container when it is monitored that a first view switch operation occurs in the application interface. The first controller found from the reuse view container is placed in the visible view container. In this embodiment, since a plurality of controllers corresponding to a plurality of views are not created, consumption of memory is reduced, and smoothness of application running is improved.
S230, acquiring data to be displayed corresponding to the first view switching operation through a first controller in the visible view container.
One of the controllers controls one view displayed in the application interface, and the view content to be displayed by the controller is determined by the attribute of the control triggered when the user sends out the first view switching operation. Specifically, the user triggers a control of the application program interface to trigger a first view switching operation, the terminal can send a view switching request to the server according to the attribute of the triggered control, and the first view switching operation corresponds to the triggered control, so that the view switching request carries display requirement information corresponding to the first view switching operation. And searching the data to be displayed corresponding to the first view switching operation by the server according to the display requirement information through a first controller in the visible view container, and returning the data to be displayed corresponding to the first view switching operation to the terminal, wherein the data to be displayed corresponding to the first view switching operation is acquired by the terminal. Or when the user triggers a control of the application program interface to trigger the first view switching operation, the terminal can obtain the data to be displayed corresponding to the first view switching operation from the local cache through the first controller in the visible view container.
S240, displaying the corresponding target view in the application interface according to the acquired data to be displayed.
The data to be displayed refers to content data corresponding to a target view which is expected to be displayed in an application interface by a user. Specifically, the terminal acquires data to be displayed corresponding to the first view switching operation, and displays a corresponding target view in an application interface according to the data to be displayed, so as to achieve the purpose of interaction with a user.
In this embodiment, the first view switching operation occurring in the application interface is monitored; if the first view switching operation is monitored, searching a first controller waiting for reuse from the reuse view container, and placing the searched first controller into the visible view container; acquiring data to be displayed corresponding to a first view switching operation through a first controller in a visible view container; and displaying the corresponding target view in the application interface according to the acquired data to be displayed. By creating the reuse view container and repeatedly utilizing the controllers in the reuse view container to display, the memory explosion caused by creating a plurality of controllers in the traditional technology is avoided, and the technical problem of the application program operation blocking is solved.
In one embodiment, as shown in fig. 3, if a first controller waiting for reuse is searched from the reuse view container, and the searched first controller is placed in the visible view container, including:
s310, judging whether a first controller waiting for reuse exists in the reuse view container;
s320, if the first controller waiting for reuse exists, searching the first controller waiting for reuse from the reuse view container, and placing the searched first controller into the visible view container.
Specifically, the running application program needs to display multiple views in the current application interface, and one view corresponds to one controller, so that memory explosion caused by creating the controller is avoided, and in this embodiment, a reuse view container is created in advance. When the first view switching operation of the application interface is monitored, judging whether a first controller exists in the reuse view container, if the first controller exists, the first controller can be reused, namely, the first controller waiting for reuse exists in the reuse view container, and when the first view switching operation is monitored, a new controller is not required to be created, and the first controller searched from the reuse view container is put into a visible view container for displaying a corresponding target view in the application interface.
In one embodiment, as shown in fig. 4, after determining whether there is a first controller waiting for reuse in the reuse view container, the method further comprises:
s410, if no first controller waiting for reuse exists, a second controller is created and placed in the visible view container.
Specifically, when the first view switching operation of the application interface is monitored, judging whether the first controller exists in the reuse view container, and if the first controller does not exist, indicating that the first controller which can be reused does not exist. A second controller is created and the created second controller is placed into the visual view container. The view content to be displayed by the second controller is also determined by the attribute of the control triggered when the user sends out the first view switching operation.
S420, acquiring data to be displayed corresponding to the first view switching operation through a second controller in the visible view container.
Specifically, the user triggers a control of the application program interface to trigger a first view switching operation, the first view switching operation corresponds to the triggered control, and the terminal can send a view switching request to the server according to the attribute of the triggered control, and the view switching request carries display requirement information corresponding to the first view switching operation. And searching the data to be displayed corresponding to the first view switching operation by the server according to the display requirement information through a second controller in the visible view container, and returning the data to be displayed corresponding to the first view switching operation to the terminal, wherein the data to be displayed corresponding to the first view switching operation is acquired by the terminal. Or, through a second controller in the visible view container, the terminal can obtain data to be displayed corresponding to the first view switching operation from the local cache.
In this embodiment, if the first controller is not in the reuse view container, the second controller is created and placed in the visible view container, so as to achieve the purpose of interaction with the user. It will be appreciated that when the user again triggers the application interface to switch views, i.e., the second controller is not required to control the views presented by the application interface, the second controller may be placed from the visual view container into the reuse view container to await reuse.
In one embodiment, after placing the first controller found within the visual view container, the method further comprises: the first controller to be found waiting for reuse is deleted from the reuse view container.
In particular, to free up memory, after the first controller in the reuse view container is placed within the visible view container, the first controller may be deleted from the reuse view container instead of staying in memory.
In one embodiment, as shown in fig. 5, after displaying the corresponding target view in the application interface according to the acquired data to be displayed, the method further includes the following steps:
s510, monitoring a second view switching operation in the application interface;
s520, judging whether the target view partially appears in the application interface;
s530, if the second view switching operation is monitored, and the target view part appears in the application interface, the first controller is kept in the visible view container.
Specifically, when a new target view needs to be displayed in the application interface, the user triggers a second view switching operation in the application interface. When the second view switching operation is triggered, the original target view may remain partially in the application interface for a period of time since the second view switching operation may last. For example, when the user performs a sliding operation on the application interface, a part of the original target view and a part of the new target view appear in the application interface. The first controller is not deleted by the visual view container, but is retained for a period of time during which the second view switching operation continues. When the user needs to view the original target view, the application program interface can quickly display the original target view.
In one embodiment, the method further comprises: and if the second view switching operation is monitored and the target view disappears in the application interface, deleting the first controller from the visible view container.
Specifically, when a new target view needs to be displayed in the application interface, the user triggers a second view switching operation in the application interface. When the second view switching operation is triggered, the original target view is disappeared in the application interface, which indicates that the application interface does not need to display the original target view, and the first controller for controlling the display of the original target view can be deleted from the visible view container, so that the memory occupied by the controller is reduced.
In one embodiment, the method further comprises: the first controller is re-placed into the reuse view container to await reuse while the first controller is deleted from the visual view container.
Specifically, if the second view switching operation is monitored, and the original target view disappears in the application interface, deleting the first controller for controlling the display of the original target view from the visual view container, and simultaneously, putting the first controller into the reuse view container again from the visual view container to wait for reuse. The method has the advantages that the fact that the visible view container is not overlapped with the controllers in the reuse view container is achieved, the controllers of the visible view container are deleted, the memory occupied by the controllers can be reduced, the controllers of the visible view container are placed in the reuse view container again, and the memory explosion caused by the controller creation is reduced.
In one embodiment, a segment control (UISegmentedControl) is used as an example to illustrate the method for switching views provided by the present application. Segment controls typically involve multiple controllers and the multiple controllers are structurally similar by creating two view containers, one for the visible view container and one for the reuse view container. As shown in fig. 6, the method comprises the steps of:
s602, monitoring a first view switching operation in an application interface.
S604, judging whether a first controller waiting for reuse exists in the reuse view container;
s606, if the first view switching operation is monitored and the first controller waiting for reuse exists, searching the first controller waiting for reuse from the reuse view container, and placing the searched first controller into the visible view container.
And S608, deleting the searched first controller waiting for reuse from the reuse view container.
S610, acquiring data to be displayed corresponding to a first view switching operation through a first controller in the visible view container.
And S612, displaying the corresponding target view in the application interface according to the acquired data to be displayed.
S614, monitoring a second view switching operation in the application interface;
s616, judging whether the target view partially appears in the application interface;
and S618, if the second view switching operation is monitored, and the target view part appears in the application interface, keeping the first controller in the visible view container.
S620, if the second view switching operation is monitored and the target view disappears in the application interface, deleting the first controller from the visible view container.
S622, the first controller is put back into the reuse view container to wait for reuse while being deleted from the visual view container.
S624, if the first view switching operation is monitored, but the first controller is not in the reuse view container, a second controller is created and placed in the visible view container;
s626, acquiring data to be displayed corresponding to the first view switching operation through a second controller in the visible view container.
It should be understood that, although the steps in the above-described flowcharts are shown in order as indicated by the arrows, these steps are not necessarily performed in order as indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described above may include a plurality of sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, and the order of execution of the sub-steps or stages is not necessarily sequential, but may be performed alternately or alternately with at least a part of the sub-steps or stages of other steps or other steps.
In one embodiment, as shown in FIG. 7, a view switching apparatus 700 is provided. The device comprises:
a switching operation monitoring module 710, configured to monitor a first view switching operation occurring in the application interface;
the controller searching module 720 is configured to search for a first controller waiting for reuse from the reuse view container and place the searched first controller into the visible view container if the first view switching operation is monitored;
a display data obtaining module 730, configured to obtain, by using a first controller in the visible view container, data to be displayed corresponding to the first view switching operation;
and the target view display module 740 is configured to display a corresponding target view in the application interface according to the acquired data to be displayed.
In one embodiment, the controller lookup module 720 is further configured to determine whether the reuse view container has a first controller waiting for reuse; if the first view switching operation is monitored and the first controller waiting for reuse exists, the first controller waiting for reuse is searched from the reuse view container, and the searched first controller is placed in the visible view container.
In one embodiment, the apparatus further comprises a controller creation module for creating a second controller and placing the second controller into the visual view container if the first view switch operation is monitored, but the first controller is not in the reuse view container;
the display data obtaining module 730 is further configured to obtain, through a second controller in the visible view container, data to be displayed corresponding to the first view switching operation.
In one embodiment, the apparatus further comprises a first deletion module for deleting the first controller that is found awaiting reuse from the reuse view container.
In one embodiment, the switching operation monitoring module 710 is further configured to monitor a second view switching operation occurring in the application interface;
the judging module is used for judging whether the target view partially appears in the application interface;
and the controller retaining module is used for retaining the first controller in the visible view container if the second view switching operation is monitored and the target view part appears in the application interface.
In one embodiment, the apparatus further includes a second deletion module configured to delete the first controller from the visual view container if the second view switching operation is monitored and the target view disappears in the application interface.
In one embodiment, the apparatus further comprises a re-placement module for re-placing the first controller into the reuse view container to await reuse while deleting the first controller from the visual view container.
For specific limitations of the view switching device, reference may be made to the above limitation of the view switching method, and the description thereof will not be repeated here. The respective modules in the above-described view switching apparatus may be implemented in whole or in part by software, hardware, and combinations thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one embodiment, a computer device is provided, which may be a terminal, and the internal structure thereof may be as shown in fig. 8. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a view switching method. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, can also be keys, a track ball or a touch pad arranged on the shell of the computer equipment, and can also be an external keyboard, a touch pad or a mouse and the like.
It will be appreciated by those skilled in the art that the structure shown in FIG. 8 is merely a block diagram of some of the structures associated with the present inventive arrangements and is not limiting of the computer device to which the present inventive arrangements may be applied, and that a particular computer device may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
In one embodiment, a computer device is provided comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method steps in the above embodiments when the computer program is executed.
In an embodiment, a computer-readable storage medium is provided, on which a computer program is stored which, when being executed by a processor, implements the method steps of the above embodiments.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in embodiments provided herein may include non-volatile and/or volatile memory. The nonvolatile memory can include Read Only Memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link DRAM (SLDRAM), memory bus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
The technical features of the above-described embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above-described embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above examples illustrate only a few embodiments of the application, which are described in detail and are not to be construed as limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of protection of the present application is to be determined by the appended claims.