Disclosure of Invention
The purpose of the invention is: the method and the device for modifying the mobile terminal interface, the computer terminal equipment and the medium can solve the problem of modifying the UI interface in the frame when the source code corresponding to the frame cannot be obtained.
In order to achieve the above object, the present invention provides a method for modifying a mobile terminal interface, including:
obtaining layer information of an interface to be modified, wherein the layer information comprises a class name of the interface to be modified;
Creating a classification corresponding to the class of the interface to be modified;
modifying the lifecycle method of the interface to be modified in the classification;
in the modified lifecycle method, the new interface is redrawn or adjusted.
In a certain embodiment, before the obtaining of the layer information of the interface to be modified, the method further includes:
displaying an interface to be modified in a Framework of a mobile terminal Framework through an Xcode integrated development tool;
and acquiring the layer information of the interface to be modified through a debugging tool of the Xcode integrated development tool.
In an embodiment, the method for modifying the life cycle of the interface to be modified in the classification further includes:
rewriting the life cycle method of the interface to be modified in the classification to obtain the life cycle method of a new interface; and the new interface is provided with a new UI and UI logic corresponding to the new UI.
In one embodiment, before the method for modifying the lifecycle of the interface to be modified in the classification, the method includes:
creating a lifecycle method for a new interface in the classification;
the method for modifying the lifecycle of the interface to be modified in the classification includes:
In the classification, the life cycle method of the interface to be modified is exchanged into the life cycle method of a new interface through an exchange method; wherein the new interface has a new UI and an old UI logic of the interface to be modified.
In one embodiment, in the classifying, exchanging the lifecycle method of the interface to be modified into the lifecycle method of the new interface by an exchange method includes:
and when the + load method is called and is called only once, exchanging the life cycle method of the interface to be modified into the life cycle method of a new interface through a runtime exchange method.
In one embodiment, after redrawing or adjusting the new interface in the modified lifecycle method, the method further includes:
and acquiring all methods and attributes in the class, and combining the new UI of the new interface with the old UI logic of the interface to be modified according to the old UI logic relationship of the interface to be modified to acquire the new interface with the new UI and the old UI logic of the interface to be modified.
In one embodiment, the obtaining method of the old UI logical relationship of the interface to be modified includes:
directly judging the old UI logical relationship of the interface to be modified according to the method name of the life cycle method of the interface to be modified in the class of the interface to be modified; or
And reversely judging the old UI logical relationship of the interface to be modified according to the printing information added by the life cycle method of the interface to be modified and the subsequent logic action.
The embodiment of the present invention further provides a modification device for a mobile terminal interface, including:
the system comprises an acquisition module, a modification module and a modification module, wherein the acquisition module is used for acquiring layer information of an interface to be modified, and the layer information comprises a class name of the interface to be modified;
the creation module is used for creating a classification corresponding to the class of the interface to be modified;
the modification module is used for modifying the life cycle method of the interface to be modified in the classification;
and the new interface generation module is used for redrawing or adjusting the new interface in the modified life cycle method.
The embodiment of the invention also provides computer terminal equipment which comprises one or more processors and a memory. A memory coupled to the processor for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the method for modifying a mobile terminal interface according to any of the embodiments described above.
The embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for modifying a mobile terminal interface in any of the above embodiments.
Compared with the prior art, the method and the device for modifying the mobile terminal interface, the computer terminal equipment and the computer readable storage medium have the advantages that:
the method and the device can modify the interface of the mobile terminal in the frame which can not obtain the source code, have simple operation, are convenient for modifying the UI interface in the frame in the development process, and improve the development efficiency.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be understood that the step numbers used herein are for convenience of description only and are not used as limitations on the order in which the steps are performed.
It is to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the specification of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
The terms "comprises" and "comprising" indicate the presence of the described features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
The term "and/or" refers to and includes any and all possible combinations of one or more of the associated listed items.
Referring to fig. 1, an embodiment of the present invention provides a method for modifying a mobile terminal interface, including the following steps:
s10, obtaining layer information of an interface to be modified, wherein the layer information comprises a class name of the interface to be modified;
S20, creating a classification corresponding to the class of the interface to be modified;
s30, modifying the life cycle method of the interface to be modified in the classification;
s40, redrawing or adjusting the new interface in the modified lifecycle method.
In the embodiment of the invention, the interfaces displayed by the mobile terminal can be modified. The mobile terminal interface comprises a UI and corresponding logic. Therefore, the mobile terminal interface modification method includes two ways:
1) modify the UI of the interface in the Framework, leaving no logic for the old interface UI. Specifically, the method for the lifecycle of the new interface is obtained by modifying the old UI of the interface to be modified and deleting the old UI logic of the interface to be modified in the lifecycle methods in the classification, wherein the new interface has the new UI and the UI logic corresponding to the new UI.
2) Modify the UI of the interface in the Framework and retain any logic of the old interface UI. Specifically, the method for the lifecycle of the new interface is obtained by modifying the old UI of the interface to be modified and reserving the old UI logic of the interface to be modified in the lifecycle methods in the classification, wherein the new interface has the new UI and the old UI logic of the interface to be modified.
Taking a login button in a mobile terminal interface as an example, if the style of the login button is to be changed, layer information of the login button of the interface to be modified is obtained first, and a page class where the login button is located, such as a ViewController (the ViewController is a page class provided by the iOS system), is found. Then, a corresponding classification is created in the page class where the login button is located, and the life cycle method of the ViewController where the login button is located is rewritten or exchanged in the classification. When the user equipment is rewritten, the UI of a new login button needs to be created again, the UI of an old login button is hidden or removed, and if only the characters of the login button need to be changed, the characters can be directly modified when the login button is created. And finally, in the modified life cycle method, redrawing or adjusting a new interface, so that the modified new interface of the mobile terminal can be obtained, and thus, the interface UI in the Framework is dynamically changed in the application of the mobile terminal or the application of a simulator of the mobile terminal.
Compared with the prior art, the method for modifying the interface of the mobile terminal can modify the interface of the mobile terminal in the frame which cannot acquire the source code, is simple to operate, facilitates modification of the UI interface in the frame in the development process, and improves the development efficiency.
Referring to fig. 2, in a certain embodiment, before the step S10 obtains the layer information of the interface to be modified, the method further includes the following steps:
s50, displaying an interface to be modified in a Framework of the mobile terminal Framework through an Xcode integrated development tool;
and S60, acquiring the layer information of the interface to be modified through a debugging tool of the Xcode integrated development tool.
Referring to fig. 3, in the embodiment of the present invention, an Xcode integrated development tool is used to create an engineering, integrate a mobile Framework into the engineering, and then run the engineering to show a relevant UI interface, such as an interface to be modified, in the Framework to be modified. Then, by means of a self-contained debugging tool 'debuggviewhierarchy' of the Xcode integrated development tool, the UI layer information corresponding to the interface to be modified is checked, the UI interface which needs to be replaced is found, and the corresponding class name is checked, for example, the class name is XPSDevelopmentAdvance SettingViewController, and the ViewController represents the page class provided by the iOS system.
Referring to fig. 4, in an embodiment, the step S30 is a method for modifying the life cycle of the interface to be modified in the classification, including the following steps:
s31, rewriting the life cycle method of the interface to be modified in the classification to obtain the life cycle method of a new interface; and the new interface is provided with a new UI and UI logic corresponding to the new UI.
In the embodiment of the present invention, the mobile terminal interface is modified in the following manner: and modifying the UI of the interface in the Framework, and not reserving any logic of the UI of the old interface so that the new interface has a new UI and a UI logic corresponding to the new UI. Therefore, in order to simply change the UI, any logic of the original UI is not retained, and at this time, it is only necessary to rewrite the methods related to the lifecycle in the classification (for example, viewdloaded, the viewController executes the method after loading the interface, and generally sets the UI in the method), and redraw or adjust the UI in the methods, that is, remove or hide the UI of the interface to be modified in the lifecycle method of the new interface in the classification, and build a new UI of the new interface.
Wherein rewriting lifecycle related methods in the classification operates as follows:
the method of writing the same name of the method related to the life cycle in the classification, such as the method of viewDidLoaded, etc., is provided by the iOS system. Object-C provides a property that when a classification has a method with the same name as the original class, then the classified method is executed and the method in the original class is ignored.
Referring to fig. 5, in an embodiment, after the step S20 creates the class corresponding to the class of the interface to be modified, before the step S30 modifies the lifecycle method of the interface to be modified in the class, the method further includes the following steps:
s70, creating a life cycle method of a new interface in the classification;
the step S30 is to modify the lifecycle method of the interface to be modified in the classification, including the following steps:
s32, in the classification, exchanging the life cycle method of the interface to be modified into the life cycle method of a new interface through an exchange method; wherein the new interface has a new UI and an old UI logic of the interface to be modified.
In the embodiment of the present invention, the mobile terminal interface is modified in the following manner: and modifying the UI of the interface in the Framework, and reserving any logic of the UI of the old interface so that the new interface has the new UI and the logic of the old UI of the interface to be modified.
After creating a classification for the class (such as xpsdevelopmentadvanced settingviewcontroller) corresponding to the UI interface to be modified, because the relevant logic of the old interface needs to be preserved, the content of the lifecycle method of the old interface needs to be executed, so the lifecycle method cannot be directly rewritten here, but the relevant lifecycle method is exchanged by using the exchange method. The method exchange implementation process and principle are as follows:
1) Create a new lifecycle method in the classification, for example: newViewDidLoad.
2) The + load method is implemented in the classification, and is called when the system loads the class, and is called only once, so the operation of the life cycle method exchange is implemented in the + load method. Specifically, the lifecycle method (e.g., viewDidLoad) in the old interface and the new lifecycle method (e.g., newViewDidLoad) implemented in the classification are swapped using the swapping method provided by runtime, which is a linguistic property of Object-C and is often referred to as method swizzling. Meanwhile, in order to ensure that the operations of the method exchange are not executed for multiple times and an exception occurs, a dispatch _ once method is used to wrap the code exchanged by the method, as shown in fig. 6, where the dispatch _ once method is a method provided by the system and guarantees to be executed once.
3) The principle of runtime method exchange is as follows:
Object-C calls a method, which is actually sending a message to the Object, which is received by the Object for execution at runtime. In one embodiment, the corresponding implementation code is found from the message name (method name) by: the object class has a method list to store the mapping relationship between the name of the selector (i.e. the method name) and the method implementation (i.e. the imp pointer: points to the specific code block), and the method exchange is to exchange the corresponding relationship. The effects before and after the exchange are shown in fig. 7(a) and 7(b), respectively. After the exchange is successful, although the old method name is called, the new method is implemented, so that the method exchange is realized, and the method newly added in the classification is implemented under the condition of not changing the source code of the Framework.
Referring to fig. 8, in an embodiment, in the classifying, the step S32 is to exchange the lifecycle method of the interface to be modified into the lifecycle method of the new interface by an exchange method, including:
s321, when the + load method is called and is called only once, the lifecycle method of the interface to be modified is exchanged into the lifecycle method of the new interface through a runtime exchange method.
The + load method is a method that is automatically called by the system when the iOS system loads the class into the memory, and is called only once. The + load method is provided for the system.
The calling + load method is used for exchanging other methods in the method class, firstly, the exchange is ensured when the class is loaded, the phenomenon that an old method is executed due to the fact that a new method is not exchanged when the class is used is prevented, secondly, the method is called only once, the phenomenon that exchange failure occurs due to multiple times of exchange is prevented, for example, the method A1 is required to be exchanged into the method A2, but no exchange occurs after two times of exchange (A1- > A2, A2- > A1).
Referring to fig. 9, in an embodiment, after redrawing or adjusting the new interface in the modified lifecycle method in step S40, the method further includes the following steps:
S80, acquiring all methods and attributes in the class, and combining the new UI of the new interface with the old UI logic of the interface to be modified according to the old UI logic relationship of the interface to be modified to obtain a new interface with the new UI and the old UI logic of the interface to be modified.
In the embodiment of the invention, in order to replace the UI of the old interface, the UI of the original interface can be removed or hidden, and then a new UI of the new interface is built.
In step S80, the steps of acquiring all methods of the class are: the method list of the class can be obtained through a class _ copymethodlistmethod provided by the system, then the method list is traversed, the method name is obtained through a method _ getName method provided by the system, and the method name is displayed during printing. The steps of obtaining all attributes of the class are as follows: the property list of the class can be obtained through a class _ copyPropertyList method provided by the system, then the property list is traversed, the property name is obtained through a property _ getName method provided by the system, and the property name is displayed during printing.
After all the methods and attributes in the class are obtained, the new UI of the new interface is combined with the old UI logic of the interface to be modified according to the mapping relation between the UI of the old interface and the UI logic, so that after the exchange is successful, although the system calls the old method name, the execution is the realization of the new method, and the method which is newly added in the classification is executed under the condition that the source code of the Framework is not changed.
In one embodiment, the obtaining method of the old UI logical relationship of the interface to be modified includes:
and directly judging the old UI logical relationship of the interface to be modified according to the method name of the life cycle method of the interface to be modified in the class of the interface to be modified.
Or reversely judging the old UI logical relationship of the interface to be modified according to the printing information added by the life cycle method of the interface to be modified and the subsequent executed logical action in the class of the interface to be modified.
In the embodiment of the invention, the method list of all methods can be obtained through the method (such as class _ copy method list and the like) provided in runtime, then all the methods in the method list are exchanged, and the printing information (such as the name of the printing method) is added in the exchanged method, so that the specific executed method is conveniently identified.
Therefore, there are two ways to obtain the old logical relationship of the interface to be modified:
1) judging the logical relationship based on the method name, such as if there is a login button in the UI, if there is a word pattern associated with login in the method name, the method is executed with a high probability of clicking the login button.
2) If the logical relationship cannot be judged according to the method name, all the methods in the class are exchanged, the printing information is added to the exchanged methods, and then the execution logic is determined according to the printing information.
When the corresponding logic action is executed, the corresponding method name is printed, and the approximate execution logic of the code can be judged according to the method name, so that the old UI logic relation of the interface to be modified is obtained. Continuing to take the login button in the mobile terminal interface as an example, when the login button is clicked, the lognAction is printed out, and then it can be determined that the lognAction method is the method executed by clicking the login button. If the style of the login button of the UI is required to be changed, only the old login button needs to be removed or hidden, a new login button is created again, and the click event of the new login button is set as the login action, so that the logic executed when the old login button in the SDK is clicked can be executed when the new login button is clicked, the function of combining the new UI and the old UI logic is realized, and the interface UI in the Framework of the dynamic change in the mobile terminal application or the mobile terminal simulator application is further realized.
Referring to fig. 10, an embodiment of the present invention further provides a device for modifying an interface of a mobile terminal, including:
the obtaining module 101 is configured to obtain layer information of an interface to be modified, where the layer information includes a class name of the interface to be modified;
A creating module 102, configured to create a category corresponding to the category of the interface to be modified;
a modification module 103, configured to modify the lifecycle method of the interface to be modified in the classification;
and a new interface generation module 104, configured to redraw or adjust the new interface in the modified lifecycle method.
For the specific definition of the modification device for the mobile terminal interface, reference may be made to the above definition of the modification method for the mobile terminal interface, which is not described herein again. All or part of the modules in the modification device of the mobile terminal interface can be realized by software, hardware and a combination 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.
Referring to fig. 11, an embodiment of the present invention further provides a computer terminal device, which includes one or more processors and a memory. The memory is coupled to the processor and configured to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method for modifying a mobile terminal interface in any of the above embodiments.
The processor is used for controlling the overall operation of the computer terminal equipment so as to complete all or part of the steps of the modification method of the mobile terminal interface. The memory is used to store various types of data to support the operation at the computer terminal device, which data may include, for example, instructions for any application or method operating on the computer terminal device, as well as application-related data. The Memory may be implemented by any type of volatile or non-volatile Memory device or combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic Memory, flash Memory, magnetic disk, or optical disk.
In an exemplary embodiment, the computer terminal Device may be implemented by one or more Application Specific 1 integrated circuits (AS 1C), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (PLD), a Field Programmable Gate Array (FPGA), a controller, a microcontroller, a microprocessor or other electronic components, and is configured to perform the above-mentioned method for modifying the mobile terminal interface, and achieve the technical effects consistent with the above-mentioned method.
In another exemplary embodiment, a computer readable storage medium storing a computer program is provided, and the computer program when executed by a processor implements the steps of the method for modifying a mobile terminal interface in any one of the above embodiments. For example, the computer-readable storage medium may be the memory storing the computer program, and the computer program may be executed by a processor of a computer terminal device to implement the method for modifying a mobile terminal interface, and achieve the technical effects consistent with the method.
The above description is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and substitutions can be made without departing from the technical principle of the present invention, and these modifications and substitutions should also be regarded as the protection scope of the present invention.