Disclosure of Invention
Based on this, it is necessary to provide a view switching method, apparatus, computer device and storage medium for solving the technical problem in the conventional technology that the creation of multiple controllers in one interface causes memory explosion and causes the application program to run unsmooth.
A method of view switching, the method comprising:
monitoring a first view switching operation 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 a corresponding target view in the application interface according to the acquired data needing to be displayed.
In one embodiment, the searching for the first controller waiting for reuse from the reuse view container and placing the searched first controller into the visible view container includes:
determining whether a first controller waiting for reuse exists in the reuse view container;
and 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.
In one embodiment, after the determining whether the reuse view container has a first controller waiting for reuse, the method further comprises:
if no first controller waiting for reuse exists, creating a second controller and putting the second controller into 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 placing the located first controller into the visible view container, the method further includes:
and deleting the searched first controller waiting for reuse from the reuse view container.
In one embodiment, after the displaying the corresponding target view in the application interface according to the acquired data required 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;
and 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.
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:
replacing the first controller in the reuse view container while the first controller is deleted from the visible view container.
A view switching apparatus, the apparatus comprising:
the switching operation monitoring module is used for monitoring first view switching operation generated 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 needing 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 above embodiments when executing the computer program.
A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method of any of the above embodiments.
The view switching method, the view switching device, the computer equipment and the storage medium monitor the first view switching operation generated 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 a corresponding target view in the application interface according to the acquired data needing to be displayed. By creating the reuse view container and repeatedly using the controllers in the reuse view container for display, the memory burst caused by creating a plurality of controllers in the traditional technology is avoided, and the technical problem of unsmooth running of the application program is solved.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The application provides a view switching method which can be applied to the application environment shown in fig. 1. The terminal 110 performs data interaction with the server 120 through a network, and the data interaction mode between the terminal 110 and the server 120 is not limited in the present application. The terminal 110 runs an application program and displays an interface of the application program, and a plurality of views are required to be displayed in the interface, and the views respectively correspond to corresponding controllers. The terminal 110 monitors a first view switching operation occurring in the application interface; and if the first view switching operation is monitored, searching the first controller waiting for reuse from the reuse view container, and placing the searched first controller into the visible view container. Through the first controller in the visible view container, the terminal 110 obtains 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 needing to be displayed. The terminal 110 may obtain data to be displayed from the local cache, or may obtain data to be displayed from the server 120. Specifically, a view switching request is initiated to the server 120 through the first view switching operation terminal 110, the server 120 receives the view switching request, the view switching request carries display requirement information corresponding to the first view switching operation, and data to be displayed corresponding to the first view switching operation is returned to the terminal 110 through the first controller server 120 in the visible view container according to the display requirement information, wherein the terminal 110 may be, but is not limited to, various personal computers, notebook computers, smart phones, 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 an embodiment, as shown in fig. 2, a view switching method is provided, which is described by taking the method as an example applied to the terminal in fig. 1, and includes the following steps:
s210, monitoring first view switching operation in the application interface.
In which a running application 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 show 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 a triggering operation such as a left-right slide or an up-down slide that is issued on the application interface. Specifically, whether a trigger operation occurs in the application interface is monitored, and if the trigger operation occurs in the application interface, whether the trigger operation is a first view switching operation is determined, that is, 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 a target view which is 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 visible view container refers to a view container for accommodating a controller corresponding to a current visible view in an application interface.
Specifically, the running application needs to display multiple views in the current application interface without creating corresponding multiple controllers. But when the first view switching operation in the application interface is monitored, the first controller waiting for reuse is sought to be searched from the reuse view container created in advance. The first controller found from the reuse view container is placed in the visible view container. In this embodiment, because a plurality of controllers corresponding to a plurality of views are not created, the consumption of memory is reduced, and the running smoothness of the application program is improved.
And S230, acquiring data needing to be displayed corresponding to the first view switching operation through a first controller in the visible view container.
The controller controls one view displayed in the application interface, and the content of the view to be shown by the controller is determined by the property of the control triggered when the user sends out the first view switching operation. Specifically, a user triggers a certain control of the application program interface to trigger a first view switching operation, the terminal may 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. Through the first controller in the visible view container, the server searches the data to be displayed corresponding to the first view switching operation according to the display requirement information, and returns the data to be displayed corresponding to the first view switching operation to the terminal, so that the terminal acquires the data to be displayed corresponding to the first view switching operation. Or when the user triggers a certain control of the application program interface to trigger the first view switching operation, the terminal can acquire 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.
And S240, displaying the corresponding target view in the application interface according to the acquired data needing to be displayed.
The data to be displayed refers to content data corresponding to a target view which a user desires to show in the application interface. 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 interacting with a user.
In the embodiment, a first view switching operation occurring in an 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 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 needing to be displayed. By creating the reuse view container and repeatedly using the controllers in the reuse view container for display, the memory burst caused by creating a plurality of controllers in the traditional technology is avoided, and the technical problem of unsmooth running of the application program 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, the method includes:
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 a plurality of views in the current application interface, and one view corresponds to one controller, so as to avoid memory explosion caused by creating the controller, and in this embodiment, a reuse view container is created in advance. When monitoring that the application interface has a first view switching operation, judging whether the reuse view container has a first controller, if so, indicating that the first controller can be reused, namely, the reuse view container has a first controller waiting for reuse, and then, monitoring that the first view switching operation does not need to create a new controller, but putting the first controller searched from the reuse view container into a visible view container so as to be used 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:
and S410, if no first controller waiting for reuse exists, creating a second controller and putting the second controller into the visible view container.
Specifically, when monitoring that the application interface generates a first view switching operation, judging whether the reuse view container has a first controller, and if not, indicating that no reusable first controller exists. A second controller is created and placed within the visible 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.
And S420, acquiring data needing to be displayed corresponding to the first view switching operation through a second controller in the visible view container.
Specifically, a user triggers a certain control of an application program interface to trigger a first view switching operation, the first view switching operation corresponds to the triggered control, and a terminal can send a view switching request to a server according to the attribute of the triggered control, where 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, so that the terminal acquires the data to be displayed corresponding to the first view switching operation. Or, the terminal may obtain, from the local cache, data to be displayed corresponding to the first view switching operation through the second controller in the visible view container.
In this embodiment, if the reuse view container does not have the first controller, the second controller is created and placed in the visible view container, so as to achieve the purpose of interacting 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 view presented by the application interface, the second controller may be placed from the visible view container into the reuse view container to await reuse.
In one embodiment, after placing the found first controller into the visible view container, the method further comprises: and deleting the searched first controller waiting for reuse from the reuse view container.
Specifically, to free memory, after the first controller in the reuse view container is placed into the visible view container, the first controller may be deleted from the reuse view container instead of staying in memory.
In an embodiment, as shown in fig. 5, after displaying a corresponding target view in an application interface according to the acquired data that needs to be displayed, the method further includes the following steps:
s510, monitoring second view switching operation in the application interface;
s520, judging whether a target view partially appears in the application interface;
and S530, 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.
Specifically, when a new target view needs to be presented in the application interface, the user may trigger a second view switching operation in the application interface. When the second view switching operation is triggered, the second view switching operation may last for a period of time, and the original target view may still be partially retained in the application interface during the period of time. For example, when the user slides the application interface left and right or up and down, part of the original target view and part of the new target view appear in the application interface. The visible view container does not delete the first controller but retains the first controller 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 presented in the application interface, the user may trigger a second view switching operation in the application interface. When the second view switching operation is triggered, the original target view disappears 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 replaced in the reuse view container to await reuse while the first controller is removed from the visible view container.
Specifically, if the second view switching operation is monitored, and the original target view disappears in the application interface, the first controller controlling the display of the original target view is deleted from the visible view container, and meanwhile, the first controller is placed into the reuse view container again from the visible view container to wait for reuse. The controller in the visible view container and the controller in the reuse view container are not overlapped, the controller for deleting the visible view container can reduce the memory occupied by the controller, and the controller for replacing the visible view container into the reuse view container reduces the memory burst caused by creating the controller.
In one embodiment, a segment control (UISegmentedControl) is taken as an example to describe the view switching method provided by the present application. A segmented control will 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 reused view container. As shown in fig. 6, the method comprises the steps of:
and S602, monitoring a first view switching operation in the 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, the first controller waiting for reuse is searched from the reuse view container, and the searched first controller is placed into the visible view container.
And S608, deleting the searched first controller waiting for reuse from the reuse view container.
S610, acquiring data needing to be displayed corresponding to the 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 needing to be displayed.
S614, monitoring 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.
And 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 placed into the reuse view container again to wait for reuse while the first controller is deleted from the visible view container.
S624, if the first view switching operation is monitored, but the reuse view container does not have the first controller, creating a second controller and putting the second controller into the visible view container;
and S626, acquiring data needing 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, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least a portion of the steps in the above-described flowcharts may include multiple sub-steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of performing the sub-steps or the stages is not necessarily sequential, but may be performed alternately or alternatingly with other steps or at least a portion of the sub-steps or stages of other steps.
In one embodiment, as shown in FIG. 7, a view switching apparatus 700 is provided. The device includes:
a switching operation monitoring module 710, configured to monitor a first view switching operation occurring in an application interface;
a controller searching module 710, configured to search, if a first view switching operation is monitored, a first controller to be reused from the reuse view container, and place the searched first controller in the visible view container;
a display data obtaining module 730, configured to obtain, through 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 710 is further configured to determine whether there is a first controller waiting for reuse in the reuse view container; and 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.
In one embodiment, the apparatus further comprises a controller creation module for creating a second controller and placing into the visible view container if the first view switching operation is monitored but there is no first controller in the reuse view container;
the display data obtaining module 730 is further configured to obtain data to be displayed corresponding to the first view switching operation through the second controller in the visible view container.
In one embodiment, the apparatus further comprises a first deletion module for deleting the found first controller waiting for 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 reserving module is used for reserving 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 comprises a second deletion module configured to delete the first controller from the visible 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 replace module to replace the first controller in the reuse view container to await reuse while the first controller is removed from the visible view container.
For the specific definition of the view switching device, reference may be made to the above definition of the view switching method, which is not described herein again. The various modules in the view switching apparatus described above may be implemented in whole or in part by software, hardware, and combinations thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram 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 comprises a nonvolatile 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 an operating system and computer programs in the non-volatile storage medium. 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, a key, a track ball or a touch pad arranged on the shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
Those skilled in the art will appreciate that the architecture shown in fig. 8 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain 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 of the above embodiments when executing the computer program.
In an embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which computer program, when being executed by a processor, carries out the method steps of the above-mentioned embodiments.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile 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), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.