View layout method, device, electronic device and storage medium
Through the SpacesLinearLayout view layout method, the Frame layout mechanism is used to realize the custom spacing and efficient layout of views on all iOS systems, solving the problem that UIStackView does not support custom spacing and low efficiency in iOS11 versions, achieving a simple and efficient View display.
Patent Information
- Application Number
- CN202210129474.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-11
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2042-02-11
AI Technical Summary
In iOS interface development, UIStackView control does not support custom spacing of views in versions below iOS11, and the layout based on AutoLayout is low, making it impossible to achieve simple and efficient dynamic view display.
Provides a SpacesLinearLayout view layout method, which obtains custom spacing information of subviews by receiving trigger events of the target view, and relays the view based on the Frame layout mechanism, and supports setting custom spacing of views on all iOS systems.
It realizes the custom spacing settings that support views on all iOS systems, improves the efficiency of view layout and coding simplicity, and is suitable for scenes that require dynamic control of displays such as live video displays.
Smart Images

Figure CN114527977B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of iOS development technology, and more specifically, to a view layout method, device, electronic device, and computer-readable storage medium. Background Art
[0002] In iOS interface development, the linear arrangement layout of multiple views is generally achieved through Frame layout or AutoLayout layout. Among them, Frame layout refers to the layout achieved by setting the coordinates and size of the view, and AutoLayout layout refers to the layout achieved by a set of constraints that describe the layout relationship between views.
[0003] At present, in order to realize dynamic display of views with concise coding, developers generally perform view layout based on the native control UIStackView provided by iOS and implemented based on AutoLayout, or based on the StackView control that is a modified version of UIStackView.
[0004] However, the UIStackView control or StackView control is implemented based on the AutoLayout layout. Although it can realize the dynamic display of views with concise coding, it has version limitations on the one hand, that is, it does not support custom spacing of views in versions below iOS11, and its universality is poor; on the other hand, because it lays out views based on the layout relationship between views, its efficiency is much lower than the Frame layout method. Summary of the invention
[0005] The embodiments of the present disclosure provide a view layout method, device, electronic device, and storage medium, which can support setting custom spacing between views while achieving adaptive re-layout of views in a concise and efficient manner.
[0006] In a first aspect of the present disclosure, a view layout method is provided, the method comprising:
[0007] Receive target trigger events for target views;
[0008] In response to the target triggering event, acquiring a first sub-view information set, wherein the sub-view information set includes sub-view information corresponding to each sub-view in the target view, and the sub-view information includes a custom spacing of the corresponding sub-views;
[0009] According to the first sub-view information set, the target view is rearranged based on a Frame layout.
[0010] A second aspect of the present disclosure further provides a view layout device, including:
[0011] A receiving module, used for receiving a target trigger event for a target view;
[0012] a subview information set acquisition module, configured to acquire a first subview information set in response to the target trigger event, wherein the subview information set includes subview information corresponding to each subview in the target view, and the subview information includes a custom spacing of the corresponding subviews;
[0013] A layout module is used to rearrange the target view based on the Frame layout mechanism according to the first sub-view information set.
[0014] According to a third aspect of the present disclosure, there is also provided an electronic device, including:
[0015] A memory for storing executable instructions;
[0016] The processor is used to run the electronic device to execute the view layout method according to the first aspect of the present disclosure under the control of the executable instructions.
[0017] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program that can be read and executed by a computer, and the computer program is used to execute the view layout method according to the first aspect of the present disclosure when read and executed by the computer.
[0018] The beneficial effect of the present disclosure lies in that, according to an embodiment of the present disclosure, after receiving a target trigger event for a target view, in response to the target trigger event, a first sub-view information set consisting of sub-view information corresponding to each sub-view in the target view and containing custom spacing of the corresponding sub-view is obtained, and according to the first sub-view information set, the target view is re-layouted based on the Frame layout mechanism, so that setting custom spacing between views can be supported on all iOS systems; at the same time, because the sub-views in the target view are re-layouted based on the Frame layout mechanism, the view layout can be efficiently implemented while taking into account the simplicity of coding.
[0019] Other features and advantages of the present disclosure will become apparent from the following detailed description of exemplary embodiments of the present disclosure with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0021] Figure 1It is a comparative schematic diagram of the target view provided by the embodiment of the present disclosure compared with the existing view control.
[0022] Figure 2 It is a schematic diagram of the external interface provided by the target view of an embodiment of the present disclosure.
[0023] Figure 3 It is a flowchart of the view layout method provided by an embodiment of the present disclosure.
[0024] Figure 4 It is a schematic diagram of a process for setting the initial size of a subview provided by an embodiment of the present disclosure.
[0025] Figure 5 It is a schematic diagram of a view layout application provided by an embodiment of the present disclosure.
[0026] Figure 6 It is a principle block diagram of a view layout device provided in an embodiment of the present disclosure.
[0027] Figure 7 It is a schematic diagram of the hardware structure of the electronic device provided by the embodiment of the present disclosure. DETAILED DESCRIPTION
[0028] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present disclosure unless otherwise specifically stated.
[0029] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure, its application, or uses.
[0030] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered as part of the specification.
[0031] In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not limiting. Therefore, other examples of the exemplary embodiments may have different values.
[0032] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0033] <Method Example>
[0034] In view of the existing problems of poor universality and inefficiency in view layout based on the native control UIStackView provided by the iOS system, the embodiment of the present disclosure provides a view layout method based on the target view, i.e., SpacesLinearLayout. Figure 1 , which is a comparative diagram of the target view provided by the embodiment of the present disclosure compared with the existing view control. The existing UIStackView usually has the following properties: axis, alignment, distribution, and spacing, and is implemented based on AutoLayout layout. However, in terms of its attribute spacing, in UIStackView, the spacing between all its subviews is usually equal. Although support for custom spacing is added in versions above iOS11, this view does not support setting custom spacing of views in versions below iOS11; the target view provided by the embodiment of the present disclosure, namely SpacesLinearLayout, has all the existing properties of the native control UIStackView on the one hand, and at the same time, it also supports setting custom spacing of views on all iOS systems, and is implemented based on Frame layout, so that view layout can be performed more efficiently.
[0035] Specifically, the target view provided by the embodiment of the present disclosure, namely, SpacesLinearLayout, respectively has the following attributes: 1. axis, namely, the horizontal axis and the vertical axis; 2. alignment, specifically including three alignment modes, namely: a first preset alignment mode, a second preset alignment mode and a third preset alignment mode, wherein the first preset alignment mode may be a leading alignment mode, the second preset alignment mode may be a center alignment mode, and the third preset alignment mode may be a fill alignment mode; 3. distribution, specifically including three arrangement modes, namely: a first preset arrangement mode, a second preset arrangement mode and a third preset arrangement mode, wherein the first preset arrangement mode may be a fillEqually mode, the second preset arrangement mode may be a fill mode, and the third preset arrangement mode may be a natural mode.
[0036] Also, see Figure 2 , which is a schematic diagram of the external interface provided by the target view of the embodiment of the present disclosure. Figure 2As shown, interface a and interface b are interfaces for adding views respectively. The difference between the two is that interface a does not specify a custom spacing, so the default spacing will be used; while interface b specifies the spacing, that is, the parameter previousSpace, so the added view will use the specified custom spacing; interfaces c and d are interfaces for inserting views at a specified position (index), and the difference between the two is the same as the above-mentioned interfaces a and b, which will not be repeated here; in addition, interface e is an interface for removing a specified view, and interface f is an interface for removing all subviews in the target view.
[0037] Please see Figure 3 , which is a flow chart of the view layout method provided in the embodiment of the present disclosure. The method can be applied to electronic devices that provide iOS interface development services or run iOS systems. The electronic devices can be terminal devices or servers, and are not specifically limited here.
[0038] like Figure 3 As shown, the method of this embodiment may include the following steps S3100-S3300, Figure 3 , a detailed description is given on how to implement efficient view layout in the iOS system based on the target view provided by the embodiment of the present disclosure, namely, SpacesLinearLayout.
[0039] Step S3100: receiving a target trigger event for a target view.
[0040] A target trigger event refers to an event that triggers the target view to be rearranged. In the embodiments of the present disclosure, the target trigger event can be any one of the following: 1. An event indicating that a first preset change has occurred in the attribute information of the target view and / or any subview in the target view; 2. An event indicating that a second preset change has occurred in the number of subviews in the target view; 3. An event initiated by an object other than the target view and used to update the attribute information of any subview in the target view.
[0041] The first preset change may be any change in the attribute information of the target view and / or any subview in the target view, for example, any change in the attributes such as axis, alignment or distribution of the target view. The second preset change may be any change in the number of subviews in the target view, for example, any change in the number of subviews in the target view after receiving a request from another object based on the target view. Figure 2 When any one of the interfaces a to f shown operates the number of subviews, the target view is triggered to be rearranged.
[0042] Specifically, in an embodiment of the present disclosure, the target view can be triggered to automatically layout out when it detects any change in its own attribute information or the attribute information of any subview it contains, or any change in the number of subviews it contains; in addition, the target view can be triggered to layout out when an event initiated by other objects other than the target view is received to update the attribute information of the target view, such as transparency, whether to hide or display, and view size.
[0043] In specific implementation, in order to enable the target view provided by the embodiment of the present disclosure to follow the changes of the subviews in time and be rearranged, the changes of each subview in the target view can be monitored based on the key-value monitoring (KVO, Key-Value-Observer) mode, wherein the key-value monitoring, also known as the observer mode, refers to identifying a certain attribute based on a key and monitoring the changes of the key value. Since the target view may also reset the size of its subviews during the process of rearrangement, when monitoring the changes of each subview in the target view based on the key-value monitoring mode, it is necessary to first determine whether the object that triggers the change is an object other than the target view. If so, the target view is triggered to be rearranged, otherwise, it is not necessary to trigger the target view to be rearranged to avoid entering an infinite loop.
[0044] Step S3200: In response to the target trigger event, obtain a first sub-view information set, wherein the sub-view information set includes sub-view information corresponding to each sub-view in the target view, and the sub-view information includes a custom spacing of the corresponding sub-views.
[0045] After receiving the target trigger event for the target view in step S3100, the target view can be triggered to be relayed out. Before the specific relayout step is executed, the sub-view information of all sub-views in the target view is first obtained, and a first sub-view information set is constructed. Then, according to the first sub-view information set, the target view is relayed out based on the Frame layout rather than the AutoLayout layout.
[0046] In an embodiment of the present disclosure, the order of sub-view information in the first sub-view information set corresponds to the arrangement order of sub-views in the target view, that is, if the sub-view information set is {viewmsg2, viewmsg1, ..., viewmsgn}, it means that the arrangement order of sub-views in the target view is view2, view1, ..., viewn, wherein viewmsg2 represents the sub-view information of view2, viewmsg1 represents the sub-view information of view1, and viewmsgn represents the sub-view information of viewn.
[0047] In an embodiment of the present disclosure, the sub-view information may include a custom spacing of the corresponding sub-view, i.e., customspace, and may also include information such as a participation identifier, axis, alignment mode, layout mode, and view size of the corresponding sub-view, which is not specifically limited here.
[0048] It should be noted that the participation flag corresponding to the subview is information indicating whether the subview participates in the re-layout, which may specifically include first flag information indicating that the subview participates in the re-layout, and second flag information indicating that the subview does not participate in the re-layout. In specific implementation, the participation flag corresponding to the subview can be determined based on the transparency (alpha) information, hidden information, and axial parallel size information in its attribute information. For example, if the subview is fully transparent or hidden, or the size parallel to the axis is 0, its participation flag can be the first flag information, that is, indicating that it does not participate in the re-layout.
[0049] Step S3300: Re-layout the target view based on the Frame layout according to the first sub-view information set.
[0050] In one embodiment, the sub-view information also includes a layout participation identifier, and the layout participation identifier is determined based on at least one of the transparency information, hidden information and axial parallel size information of the corresponding sub-view; the re-layout of the target view based on the Frame layout according to the first sub-view information set includes: filtering the sub-view information in the first sub-view information set whose corresponding layout participation identifier is the first identification information to obtain a second sub-view information set, wherein the first identification information indicates that the corresponding sub-view does not participate in the re-layout; and re-layout the target view according to the second sub-view information set.
[0051] Specifically, before the sub-views in the target view are rearranged, since some sub-views may be displayed transparently or hidden, or their size parallel to the axis direction is 0, such sub-views usually do not occupy the display space in the target view, nor affect the arrangement and alignment of other sub-views, so such sub-views do not need to participate in the rearrangement. Therefore, before the target view is rearranged, the sub-view information of the sub-views that do not participate in the rearrangement can be filtered according to the acquired first sub-view information set to obtain a second sub-view information set consisting of the sub-view information of all sub-views participating in the rearrangement, and based on the second sub-view information set, the size and display position of all sub-views participating in the rearrangement are reset to achieve the rearrangement of the target view.
[0052] In one embodiment, the target view is rearranged according to the second sub-view information set, including: setting the initial size of all sub-views in the target view that participate in the rearrangement according to the second sub-view information set; obtaining the arrangement mode, alignment mode and total size of the target view; rearranging the size of each sub-view in all sub-views according to the arrangement mode, the total size and the initial size to obtain the target size of all sub-views; setting the position information of all sub-views according to the alignment mode; and laying out all sub-views according to the target size and the position information to complete the rearrangement of the target view.
[0053] Please see Figure 4 , which is a schematic diagram of a process for setting the initial size of a subview provided by an embodiment of the present disclosure, such as Figure 4 As shown, the processing specifically includes the following steps: step S4100, obtaining the first sub-view information of the first sub-view from the second sub-view information set, wherein the first sub-view is any sub-view of all the sub-views participating in the rearrangement; determining whether the size of the first sub-view is an externally specified size according to the first sub-view information, if so, executing step S4200, setting the first initial size of the first sub-view to the externally specified size; if not, determining whether the intrinsic size of the first sub-view is greater than a preset value according to the first sub-view information, if so, executing step S4300, setting the first initial size to the intrinsic size; if not, executing step S4400, obtaining the first initial size based on the preset constraint calculation corresponding to the target image; and, according to the first initial size, setting the initial sizes of all sub-views participating in the rearrangement in the target view.
[0054] The external specified size is for external objects, that is, other objects outside the target view are the sizes set for the corresponding subviews.
[0055] Specifically, since this method uses the Frame layout to achieve the rearrangement of the target view, if the size of the subview in the target view has been set by an external object, that is, by an object other than the target view, for example, its frame has been set, then the size of the frame can be directly used as the size of the subview, that is, frame.size is used as the initial size of the subview. If the subview has not been set by an external object, it is necessary to determine whether the intrinsic size of the subview, that is, the intrinsic size (intrinsicContentSize) is greater than a preset value. If it is, the intrinsic size can be directly used as the initial size of the subview. Otherwise, it is necessary to calculate the optimal size of each subview based on the preset constraints of the target view as its initial size, wherein the preset value can be 0, or it can also be other values, which are not specifically limited here.
[0056] According to the above description, the target view can include three preset layout modes, specifically the first preset layout mode, namely the fillEqually mode, the second preset layout mode, namely the fill mode, and the third preset layout mode, the natural mode. Therefore, after determining the initial size of all subviews involved in the rearrangement, it is also necessary to rearrange each subview according to the layout mode of the target view and the total size of the target view so that its size can adapt to the total size of the target view. The following explains how to set the size of each subview in different layout modes.
[0057] In one embodiment, the method of resetting the size of each sub-view in all sub-views according to the arrangement mode, the total size and the initial size to obtain the target size of all sub-views includes: when the arrangement mode is the first preset mode, obtaining a first sum value of the custom spacing of the target sub-view according to the second sub-view information set, wherein the target sub-view is a sub-view other than the first sub-view of the target view in all sub-views; calculating the difference between the total size and the first sum value; when the difference is not less than a preset value, obtaining the number of all sub-views participating in the rearrangement, and taking the difference divided by the number as the target size; and, when the difference is less than the preset value, setting the target size to the preset value.
[0058] The first subview refers to the subview that is located at the first position of the target view in the arrangement order, that is, the subview at the frontmost position. For the sake of layout aesthetics, the custom spacing of the subview that is usually located at the first position of the target view is not effective.
[0059] Specifically, s t Indicates the total size of the target view, s 1 Denote the first sum, and Δd1 denote the difference, then Δd1 = s t -s 1 ; In the specific implementation, after Δd1 is calculated, the size of the remaining space in the target view after removing the custom spacing of all subviews can be obtained, and then the subviews participating in the rearrangement can divide the remaining space equally; of course, if the size obtained after equal division is smaller than the preset value, for example, less than 0, in order to avoid errors, the target size of each subview is directly set to the preset value, for example, set to 0.
[0060] In one embodiment, the method of resetting the size of each sub-view in all sub-views according to the arrangement mode, the total size and the initial size to obtain the target size of all sub-views includes: when the arrangement mode is the second preset mode, obtaining a first sum of the custom spacings of the target sub-views participating in the re-layout according to the second sub-view information set, wherein the target sub-view is a sub-view in all sub-views except the first sub-view of the target view; obtaining a second sum of the initial sizes of all sub-views and the first sum; and resetting the size of each sub-view in all sub-views according to the second sum and the total size to obtain the target size of all sub-views.
[0061] Specifically, the method of resetting the size of each subview in all subviews according to the second sum and the total size to obtain the target size of all subviews includes: when the second sum is not equal to the total size, performing size change processing on all subviews in sequence according to the size change priority order corresponding to each subview in all subviews, and in the process of performing the size change processing in sequence, updating the second sum according to the transformed size of the corresponding subview; when the updated second sum is equal to the total size, stopping the size transformation processing and taking the current size of all subviews as the target size; wherein the size transformation processing includes a size stretching subprocessing and a size compression subprocessing.
[0062] In this embodiment, s t Indicates the total size of the target view, s 2 represents the second sum value, then when the second sum value is not equal to the total size, all subviews are sequentially processed for size change according to the size change priority order corresponding to each subview in all subviews, including: t Less than s 2 In the case of s, all subviews are compressed in sequence according to the compression priority order corresponding to each subview in all subviews; and t Greater than s 2 In the case of stretching, all subviews are stretched in sequence according to the stretching priority order corresponding to each subview in all subviews.
[0063] Specifically, when the total size of the target view is smaller than the second sum of the initial sizes of all subviews and their custom spacing, each subview may be compressed in turn according to the compression priority order pre-set for each subview until the updated second sum is equal to the total size, that is, all subviews after stretching may be adaptively filled into the entire target view; and when the total size of the target view is larger than the second sum, each subview may be stretched according to the stretching priority order pre-set for each subview. Usually, it is only necessary to directly stretch the subview with the first stretching priority until the updated second sum is equal to the total size.
[0064] In addition, the resetting of the size of each sub-view in all sub-views according to the arrangement mode, the total size and the initial size to obtain the target size of all sub-views includes: when the arrangement mode is the third preset mode, directly using the initial size of all sub-views as the target size. That is, when the arrangement mode of the target view is natural, there is no need to perform special processing on the size of each sub-view, and its initial size can be kept as the final size.
[0065] After completing the adaptive size setting of all sub-views participating in the rearrangement in the target view through the above steps, setting the position information of all sub-views according to the alignment mode includes: aligning all sub-views according to the alignment mode, and correspondingly setting the size of each sub-view perpendicular to the axial direction to set the position information of all sub-views.
[0066] Specifically, according to the alignment mode of the target view, that is, all subviews participating in the rearrangement can be aligned, and the coordinate data after the alignment can be used as the position information of the corresponding subview. During the alignment process, the size of the subview perpendicular to the axis, that is, the size of the axis, can be adjusted at the same time. Specifically, when the alignment mode of the target view is the fill mode, that is, the fill mode, the size of each subview perpendicular to the axis can be adjusted to the size of the target view, otherwise no adjustment is made. In addition, when the target view is arranged horizontally from right to left, the horizontal coordinates of each subview can be adapted, and the specific processing will not be repeated here.
[0067] After adaptively setting the target size and position information of each subview involved in the rearrangement according to the target view's arrangement mode and alignment mode, each subview can be laid out in turn based on the target size and position information and the iOS system's Frame layout interface. After completing the layout of the first subview, each subview can be laid out according to the next subview's custom spacing and its target size and position information to complete the rearrangement of the target view.
[0068] Please see Figure 5 , which is a schematic diagram of a view layout application provided by an embodiment of the present disclosure, such as Figure 5 As shown in the content in the black solid box, it contains multiple view elements in the vertical direction and the spacing between them is not equal. Moreover, since it is a live broadcast scene, the view elements displayed are also dynamically determined according to the configuration sent by the server. This means that if the view layout in this scene is implemented based on the native control UIStackView, when displaying each frame, it is necessary to determine whether the view elements need to be displayed based on the configuration sent by the server, and redefine their spacing according to the displayed view elements. On the one hand, this has requirements for the version of the iOS system and requires more complex business processing logic. The view layout method provided by the embodiment of the present disclosure can be processed under all iOS systems. On the other hand, it only needs to be adaptively re-layouted according to the updated attribute information of the view elements, so that the view layout can be implemented with simpler coding and high efficiency.
[0069] In summary, the view layout method based on the target view, i.e., SpaceLinerLayout, provided by the embodiment of the present disclosure is more universal than the native UIStackView layout method in the iOS system, i.e., it can meet the requirements for setting custom spacing of views in all iOS systems; on the other hand, since the method provided by the present embodiment is based on the Frame layout for view layout, it has higher layout efficiency than the UIStackView based on the AutoLayout layout; in addition, in scenarios where dynamic control of display views is required, such as live video display scenarios, view layout based on this method can make the coding more concise, easier to maintain and iteratively developed.
[0070] <Device Example>
[0071] Corresponding to the above embodiment, in this embodiment, a view layout device is also provided, such as Figure 6 As shown, the apparatus 600 may include a receiving module 610 , a sub-view information set acquiring module 620 and a layout module 630 .
[0072] The receiving module 610 is used to receive a target trigger event for a target view; the sub-view information set acquisition module 620 is used to obtain a first sub-view information set in response to the target trigger event, wherein the sub-view information set includes sub-view information corresponding to each sub-view in the target view, and the sub-view information includes a custom spacing between corresponding sub-views; the layout module 630 is used to re-layout the target view based on the Frame layout mechanism according to the first sub-view information set.
[0073] <Equipment Embodiment>
[0074] In this embodiment, an electronic device is also provided. Figure 7 As shown, the electronic device 700 may further include a processor 720 and a memory 710, wherein the memory 710 is used to store executable instructions; the processor 720 is used to operate the electronic device according to the control of the instructions to execute the view layout method according to any embodiment of the present disclosure.
[0075] <Medium Example>
[0076] Corresponding to the above method embodiments, in this embodiment, a computer-readable storage medium is also provided, which stores a computer program that can be read and executed by a computer, and the computer program is used to execute the view layout method described in any of the above embodiments of the present disclosure when read and executed by the computer.
[0077] The flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of an instruction, and the module, a program segment or a part of an instruction contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or the flowchart, and the combination of the boxes in the block diagram and / or the flowchart can be implemented by a dedicated hardware-based system that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions. It is well known to those skilled in the art that it is equivalent to implement it by hardware, implement it by software, and implement it by combining software and hardware.
[0078] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein. The scope of the present disclosure is defined by the appended claims.
Claims
1. A view layout method, characterized in that: include: Receive target trigger events for target views; In response to the target triggering event, acquiring a first sub-view information set, wherein the sub-view information set includes sub-view information corresponding to each sub-view in the target view, and the sub-view information includes a custom spacing of the corresponding sub-views; According to the first subview information set, the target view is re-layouted based on the Frame layout, Wherein, the sub-view information also includes a layout participation identifier; The re-layout of the target view based on the Frame layout mechanism according to the first sub-view information set includes: Filtering the sub-view information corresponding to the layout participation identifier of the first identification information in the first sub-view information set to obtain a second sub-view information set, wherein the first identification information indicates that the corresponding sub-view does not participate in the re-layout; According to the second subview information set, setting the initial sizes of all subviews participating in the rearrangement in the target view; Obtaining the layout mode, alignment mode and total size of the target view; Resetting the size of each subview in all subviews according to the arrangement mode, the total size and the initial size to obtain a target size of all subviews; According to the alignment mode, setting the position information of all the subviews; According to the target size and the position information, all the subviews are laid out to complete the re-layout of the target view. Wherein, the arrangement mode includes a first preset arrangement mode or a second preset arrangement mode; The resetting the size of each subview in all subviews according to the arrangement mode, the total size and the initial size to obtain the target size of all subviews includes: When the arrangement mode is the first preset arrangement mode, obtaining, according to the second sub-view information set, a first sum value of a custom spacing of a target sub-view, wherein the target sub-view is a sub-view among all the sub-views except a first sub-view of the target view; Calculate the difference between the total size and the first sum; When the difference is not less than a preset value, obtaining the number of all subviews involved in the rearrangement, and taking the difference divided by the number as the target size; and When the difference is less than the preset value, the target size is set to the preset value. When the arrangement mode is the second preset arrangement mode, obtaining, according to the second sub-view information set, a first sum value of the custom spacing of the target sub-views participating in the re-layout, wherein the target sub-view is a sub-view among all the sub-views except the first sub-view of the target view; Obtain a second sum of the initial sizes of all subviews and the first sum; The size of each sub-view in all the sub-views is reset according to the second sum value and the total size to obtain the target size of all the sub-views.
2. The method according to claim 1, characterized in that The layout participation flag is determined according to at least one of transparency information, hidden information and axial parallel size information of the corresponding subview.
3. The method according to claim 1, characterized in that The step of setting the initial sizes of all subviews participating in the rearrangement in the target view according to the second subview information set includes: Acquire first subview information of a first subview from the second subview information set, wherein the first subview is any subview among all subviews participating in the rearrangement; Determine, according to the first subview information, whether the size of the first subview is an externally specified size, and if so, set a first initial size of the first subview to the externally specified size; If not, determining whether the intrinsic size of the first subview is greater than a preset value according to the first subview information, and if so, setting the first initial size to the intrinsic size; If not, calculating and obtaining the first initial size based on a preset constraint corresponding to the target view; According to the first initial size, the initial sizes of all subviews participating in the rearrangement in the target view are set.
4. The method according to claim 1, characterized in that: The step of resetting the size of each subview in all subviews according to the second sum value and the total size to obtain the target size of all subviews includes: When the second sum is not equal to the total size, performing size change processing on all the subviews in sequence according to a size change priority order corresponding to each subview in all the subviews, and updating the second sum according to the transformed size of the corresponding subview during the size change processing; When the updated second sum is equal to the total size, stop the size transformation process and use the current sizes of all subviews as the target size; The size transformation process includes a size stretching sub-process and a size compression sub-process.
5. The method according to claim 1, characterized in that The arrangement mode includes a third preset arrangement mode; The resetting the size of each subview in all subviews according to the arrangement mode, the total size and the initial size to obtain the target size of all subviews includes: When the arrangement mode is the third preset arrangement mode, the initial sizes of all the sub-views are directly used as the target sizes.
6. The method according to claim 1, characterized in that The step of setting the position information of all subviews according to the alignment mode includes: According to the alignment mode, all the sub-views are aligned, and the size of each sub-view perpendicular to the axial direction is correspondingly set to set the position information of all the sub-views.
7. The method according to claim 1, characterized in that The target triggering event includes at least one of the following: An event indicating that a first preset change occurs to attribute information of the target view and / or any subview in the target view; An event indicating that a second preset change occurs in the number of subviews in the target view; An event initiated by an object other than the target view and used to update the property information of any subview in the target view.
8. A view layout device, characterized in that: include: A receiving module, used for receiving a target trigger event for a target view; a subview information set acquisition module, configured to acquire a first subview information set in response to the target trigger event, wherein the subview information set includes subview information corresponding to each subview in the target view, the subview information includes a custom spacing of the corresponding subviews, and the subview information also includes a layout participation identifier; a layout module, configured to re-layout the target view based on the Frame layout mechanism according to the first sub-view information set, Wherein, the layout module is specifically used for: Filtering the sub-view information corresponding to the layout participation identifier of the first identification information in the first sub-view information set to obtain a second sub-view information set, wherein the first identification information indicates that the corresponding sub-view does not participate in the re-layout; According to the second subview information set, setting the initial sizes of all subviews participating in the rearrangement in the target view; Obtaining the layout mode, alignment mode and total size of the target view; Resetting the size of each subview in all subviews according to the arrangement mode, the total size and the initial size to obtain a target size of all subviews; According to the alignment mode, setting the position information of all the subviews; According to the target size and the position information, all the subviews are laid out to complete the re-layout of the target view. Wherein, the arrangement mode includes a first preset arrangement mode or a second preset arrangement mode; When the layout module resets the size of each sub-view in all sub-views according to the arrangement mode, the total size and the initial size to obtain the target size of all sub-views, the layout module is specifically used to: When the arrangement mode is the first preset arrangement mode, obtaining, according to the second sub-view information set, a first sum value of a custom spacing of a target sub-view, wherein the target sub-view is a sub-view among all the sub-views except a first sub-view of the target view; Calculate the difference between the total size and the first sum; When the difference is not less than a preset value, obtaining the number of all subviews involved in the rearrangement, and taking the difference divided by the number as the target size; and When the difference is less than the preset value, the target size is set to the preset value. When the arrangement mode is the second preset arrangement mode, obtaining, according to the second sub-view information set, a first sum value of the custom spacing of the target sub-views participating in the re-layout, wherein the target sub-view is a sub-view among all the sub-views except the first sub-view of the target view; Obtain a second sum of the initial sizes of all subviews and the first sum; The size of each sub-view in all the sub-views is reset according to the second sum value and the total size to obtain the target size of all the sub-views.
9. An electronic device, characterized in that: include: A memory for storing executable instructions; A processor is used to operate the electronic device to execute the view layout method as described in any one of claims 1-7 under the control of the instruction.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program that can be read and executed by a computer, and the computer program is used to execute the view layout method according to any one of claims 1 to 7 when being read and executed by the computer.
