View adjustment method and device of navigation bar, medium, equipment and program product
By creating navigation bar classification in iOS application development and adjusting the borders of navigation bar buttons, the problem of inconsistent spacing between navigation bar buttons and screen edges is solved, the interface aesthetics and consistency is improved, and development and maintenance costs are reduced.
Patent Information
- Application Number
- CN202411909169.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-05-30
AI Technical Summary
In iOS application development, the spacing between the left and right buttons of the navigation bar are inconsistent with the edge of the screen, which affects the beautiful interface and reduces the user experience. Manual adjustment of the spacing is cumbersome and error-prone, which increases the development difficulty and maintenance costs.
By creating a navigation bar category, loop through the parent view of the navigation bar button under the navigation bar category, get the layout margin attribute values of the parent view, and adjust the border of the navigation bar button according to these attribute values to achieve the target spacing from the edge of the screen.
Ensure that the spacing between the navigation bar buttons and the edge of the screen on different models and system versions is consistent, which improves the aesthetics and consistency of the application interface and reduces development difficulty and maintenance costs.
Smart Images

Figure CN120066497A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of view adjustment, and specifically to a method, device, medium, equipment, and program product for adjusting the view of a navigation bar. Background Art
[0002] In the field of iOS application development, the navigation bar (UINavigationBar) plays a key role in navigation, information display, and providing operation buttons. However, in practical applications, the problem that the spacing between the left and right buttons of the navigation bar and the screen edge is inconsistent often occurs, which not only affects the interface aesthetics but also may reduce the user experience.
[0003] Specifically, the button spacing of the navigation bar in the iOS system is default controlled by the system, but due to differences in devices, system versions, or customization requirements, the spacing may change. For example, when the system font, screen size, or navigation bar height changes, the button spacing may be inconsistent; when adding custom buttons, the spacing may also be uneven due to the lack of a unified layout specification.
[0004] To solve this problem, developers often need to manually adjust the button spacing to ensure consistency across different devices and system versions. However, this method is cumbersome and error-prone. Especially when dealing with devices with multiple screen sizes and resolutions, it is necessary to set the spacing separately for each device, increasing the development difficulty and maintenance cost. Summary of the Invention
[0005] Embodiments of this application provide a method, device, medium, equipment, and program product for adjusting the view of a navigation bar, which can ensure that the spacing between the navigation bar buttons and the screen edge remains consistent on different models and different system versions, improving the aesthetics and consistency of the application interface, and reducing the development difficulty and maintenance cost.
[0006] On the one hand, embodiments of this application provide a method for adjusting the view of a navigation bar, the method including:
[0007] Create a navigation bar category, and loop through the parent views of the navigation bar buttons under the navigation bar category to obtain the layout margin attribute values of the parent views;
[0008] Adjust the border of the navigation bar buttons according to the layout margin attribute values of the parent views to achieve the target spacing between the navigation bar buttons and the screen edge of the terminal device;
[0009] Display the navigation bar at the target spacing according to the target spacing.
[0010] On the other hand, embodiments of this application provide a device for adjusting the view of a navigation bar, the device including:
[0011] A processing unit, configured to create a navigation bar classification, and loop through the parent views of the navigation bar buttons under the navigation bar classification to obtain the layout margin attribute values of the parent views;
[0012] An adjustment unit, configured to adjust the border of the navigation bar button according to the layout margin attribute value of the parent view, so as to achieve a target spacing between the navigation bar button and the screen edge of the terminal device;
[0013] A display unit, configured to display the navigation bar at the target spacing according to the target spacing.
[0014] On the other hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program, and the computer program is suitable for being loaded by a processor to execute the view adjustment method of the navigation bar described in any of the above embodiments.
[0015] On the other hand, an embodiment of the present application provides a computer device, which includes a processor and a memory. The memory stores a computer program, and the processor is configured to execute the view adjustment method of the navigation bar described in any of the above embodiments by calling the computer program stored in the memory.
[0016] On the other hand, an embodiment of the present application provides a computer program product, which includes computer instructions, and when the computer instructions are executed by a processor, the view adjustment method of the navigation bar described in any of the above embodiments is implemented.
[0017] In the embodiments of the present application, by creating a navigation bar classification and looping through the parent views of the navigation bar buttons under the navigation bar classification to obtain the layout margin attribute values of the parent views; adjusting the border of the navigation bar button according to the layout margin attribute value of the parent view to achieve a target spacing between the navigation bar button and the screen edge of the terminal device; and displaying the navigation bar at the target spacing according to the target spacing. The embodiments of the present application provide convenience for expanding and modifying the functions of the navigation bar by creating a navigation bar classification, and at the same time avoid directly modifying the underlying system code, ensuring the stability and security of the system; by looping through the parent views of the navigation bar buttons, accurately positioning the view hierarchy responsible for displaying the navigation bar buttons, providing an accurate target object for subsequent spacing adjustment; by obtaining the layout margin attribute values of the parent views and dynamically adjusting the border of the navigation bar button according to the layout margin attribute values, ensuring that the spacing between the navigation bar button and the screen edge remains consistent on different models and different system versions; and displaying the navigation bar according to the target spacing, making the application interface maintain consistent aesthetics and consistency in different device and system environments, and reducing the development difficulty and maintenance cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1Schematic flowchart of the view adjustment method for the navigation bar provided by the embodiments of the present application.
[0019] Figure 2 Schematic application scenario diagram of the view adjustment method for the navigation bar provided by the embodiments of the present application.
[0020] Figure 3 Schematic structural diagram of the view adjustment device for the navigation bar provided by the embodiments of the present application.
[0021] Figure 4 Schematic structural diagram of the computer device provided by the embodiments of the present application.
[0022] Figure 5 Schematic diagram of the storage medium provided by the embodiments of the present application. Detailed implementation manners
[0023] Next, in combination with the accompanying drawings in the embodiments of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative efforts fall within the protection scope of the present application.
[0024] The embodiments of the present application provide a view adjustment method, device, medium, device and program product for a navigation bar. Specifically, the view adjustment method for the navigation bar in the embodiments of the present application can be executed by a computer device, where the computer device can be a terminal or a server and other devices. The terminal can be a smart phone, a tablet computer, a notebook computer, a smart TV, a smart speaker, a wearable smart device, a smart vehicle terminal and other devices. The terminal can also include a client, and the client can be a video client, a browser client, an instant messaging client, a shopping client or a small program, etc. The server can be an independent physical server, or a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery network (Content Delivery Network, CDN), and big data and artificial intelligence platforms.
[0025] The embodiments of the present application can be applied to various scenarios such as interface design and view adjustment.
[0026] First, some nouns or terms that appear in the process of describing the embodiments of the present application are explained as follows:
[0027] Navigation Bar (UINavigationBar): It is an interface element in iOS development, usually located at the top of the screen, used to display the main navigation options of the application. It can contain the application logo, menu buttons, and other navigation elements, providing navigation and page switching functions.
[0028] System Navigation Bar Button Fixed Space (UIBarButtonSystemItemFixedSpace): It is a type of navigation bar button item (UIBarButtonItem), used to create a fixed-width interval in the navigation bar. This interval can be used to adjust the distance between other buttons.
[0029] Navigation Bar Button Item (UIBarButtonItem): This is a class in the User Interface Kit (UIKit) framework, used to represent a button item in the navigation bar. It can be a standard system button or a custom view.
[0030] Navigation Bar Button (UIBarButton): Usually refers to an object of the Navigation Bar Button Item (UIBarButtonItem) class, representing a button item in the navigation bar. It can contain an icon, text, or other custom views.
[0031] Runtime: It extends the runtime system of the object-oriented programming language Objective-C, which allows obtaining class information, adding methods, modifying method implementations, etc. dynamically during program execution. Through the runtime system, some dynamic behaviors such as method swizzling can be achieved.
[0032] Hook: A technique used to intercept and modify the normal execution flow of a program. In iOS development, the runtime mechanism is usually used to hook methods, that is, replace the implementation of a certain method, so as to execute custom logic when the method is called.
[0033] Layout Subviews: It is a method of the UIView class, used to re-layout all subviews of the view. When the bounds of the view change or re-layout is required, the system will automatically call the layoutSubviews method. Developers can override the layoutSubviews method to customize the layout of subviews.
[0034] Frame: It is a property of the UIView, representing the position and size of the view in the coordinate system of its superview. The frame can contain the x coordinate, y coordinate, width, and height of the view.
[0035] initWithCustomView: An initialization method of the UIBarButtonItem class used to create a navigation bar button item with a custom view. Through this method, any UIView object can be used as the content of the navigation bar button.
[0036] _UINavigationBarContentView: A private class representing the content view inside the navigation bar. It is responsible for managing the layout of elements such as titles and buttons in the navigation bar. In the embodiments of this application, the spacing between the navigation bar button and the screen edge is changed by finding the instance of _UINavigationBarContentView and adjusting its frame.
[0037] barContentView: This is an instance object of _UINavigationBarContentView and is used as a variable name in the code to represent a specific instance of the navigation bar content view.
[0038] layoutMargins: A property of the UIView representing the spacing between the view content and the view edge. layoutMargins can include margin values for the top, bottom, left, and right directions.
[0039] The following will be described in detail respectively. It should be noted that the description order of the following embodiments does not limit the priority order of the embodiments.
[0040] Each embodiment of this application provides a method for adjusting the view of a navigation bar. This method can be executed by a terminal or a server, or jointly executed by a terminal and a server; in the embodiments of this application, the method for adjusting the view of the navigation bar is described by taking the execution by the server as an example.
[0041] Please refer to Figures 1 to 2 , Figure 1 , which is a schematic flowchart of the method for adjusting the view of the navigation bar provided by the embodiments of this application, Figure 2 , which is a schematic diagram of the application scenario of the method for adjusting the view of the navigation bar provided by the embodiments of this application. This method may include the following steps:
[0042] Step 110: Create a navigation bar category and loop through the parent views of the navigation bar buttons under the navigation bar category to obtain the layout margin property values of the parent views.
[0043] First, create a category for the UINavigationBar, such as
[0044] UINavigationBar+ZZNavigationBarBarItemFixSpace. Here, UINavigationBar represents the navigation bar in iOS development. It is a user interface component used to display navigation elements such as titles and buttons. ZZNavigationBarBarItemFixSpace represents a custom category or extension for fixing the spacing between bar items in the navigation bar. This UINavigationBar category is used to extend the functionality of the system navigation bar without modifying the original class code.
[0045] Then, use runtime technology and adopt hook functions to call the layoutSubviews method of the UINavigationBar category. In this method, by looping through the superview of the navigation bar button, obtain the value of the layoutMargins property of this superview. The layoutMargins property value includes the left margin value (left) and / or the right margin value (right) of the layoutMargins of the superview. These two values represent the default spacing between the superview and the screen edge.
[0046] In some embodiments, the method further includes:
[0047] Set the target spacing between the navigation bar button and the screen edge;
[0048] Set a preset spacing between the navigation bar button and the screen edge. The preset spacing is half of the target spacing;
[0049] Set the hot zone range of the navigation bar button according to the difference between the target spacing and the preset spacing.
[0050] Among them, set the target spacing between the navigation bar button and the screen edge. For example, declare a global macro definition NAV_ITEM_SCREEN_SPACING, and set its value to 16. The value of this macro definition represents the target spacing that is expected to be maintained between the navigation bar button (whether it is a left button or a right button) and the screen edge. The setting of this target spacing aims to ensure that the spacing between the navigation bar button and the screen edge can maintain a consistent visual effect on different devices and screen sizes.
[0051] Among them, a preset spacing is set between the navigation bar button and the screen edge. For example, declare a global macro definition NAV_BAR_CONTENT_SCREEN_SPACING, and its value is set to 8. The value of this macro definition represents the actual preset spacing maintained between the navigation bar button (whether it is the left button or the right button) and the screen edge after adopting the unified processing method. This preset spacing is half of the target spacing, that is, NAV_ITEM_SCREEN_SPACING / 2. Such a design is to leave enough space around the navigation bar button, that is, there is still a spacing space of (NAV_ITEM_SCREEN_SPACING - NAV_BAR_CONTENT_SCREEN_SPACING)*2, so as to set the hot zone range subsequently.
[0052] Among them, according to the difference between the target spacing and the preset spacing, the hot zone range of the navigation bar button is set. In order to improve the accuracy of the user clicking the navigation bar button, the hot zone range can be calculated according to the difference between the target spacing and the preset spacing. For example, declare a global macro definition NAV_BAR_ITEM_CONTENT_INSETS_SPACE, and its value is NAV_ITEM_SCREEN_SPACING - NAV_BAR_CONTENT_SCREEN_SPACING. This macro definition represents the left and right spacing that should be reserved when the business layer generates the navigation bar button, and this left and right spacing area is the hot zone range when the user clicks.
[0053] Through such a design, even if the user's click position deviates slightly from the center of the button, as long as the user's click position falls within the hot zone range, the system can still recognize and respond to this click action. The error tolerance rate of the user's click is improved, thereby enhancing the user experience.
[0054] Among them, by introducing global macro definitions, the flexibility and maintainability of the code are improved. Once the spacing requirements in the design draft change, such as from 16 to other values, only the corresponding macro definition value needs to be modified, without having to modify the specific values in the code one by one. Such a design not only simplifies the process of code modification but also reduces the risk of errors.
[0055] In some embodiments, the method further includes:
[0056] In response to a creation instruction of a custom button, create a custom button according to the hot zone range.
[0057] For example, the system or the user triggers a creation instruction for a custom button. This creation instruction may come from an operation in the user interface, such as clicking on a menu item "Add Button", or from a call by another program. The creation instruction contains the necessary information for the custom button, such as the button title text, the button icon, and possibly other style attributes (such as font, color, etc.). The system needs to parse this information for subsequent use.
[0058] For example, based on the received information and in combination with a pre-set hot zone range (NAV_BAR_ITEM_CONTENT_INSETS_SPACE), a custom button is created. In this way, an appropriate spacing can be ensured between the button content (such as the icon or text) and the boundaries of its parent view, thus forming a larger clickable area, that is, the hot zone.
[0059] In some embodiments, the creating a custom button according to the hot zone range in response to the creation instruction of the custom button includes:
[0060] Receiving a creation instruction for a custom button, the creation instruction carrying the button title text information and / or the button icon information of the custom button;
[0061] Creating a custom button with the preset spacing according to the hot zone range, and the button title text information and / or the button icon information.
[0062] Among them, the button title text information includes the title text, the title text color, the title text font, etc.
[0063] For example, the following first code example can be used to create a custom button according to the button icon information (picture):
[0064]
[0065]
[0066] Among them, for the above first code example, it mainly includes the following steps:
[0067] (1) Create a custom button: Use the buttonWithType:UIButtonTypeCustom method of UIButton to create a custom type of button.
[0068] (2) Set the button image: Call the setImage:forState: method to set the display image for the button in the normal state.
[0069] (3) Calculate and set the border (frame) of the button: Set the width of the border to the width of the image plus twice the NAV_BAR_ITEM_CONTENT_INSETS_SPACE to ensure there is an appropriate spacing between the image on the button and the left and right margins of the button, forming a hot zone. For example, the height of the button is fixed at 40 points to ensure sufficient vertical click area.
[0070] For example, the following second code example can be used to create a custom button based on the button title text information (text):
[0071]
[0072] Among them, for the above second code example, it mainly includes the following steps:
[0073] (1) Create a custom button: Use the buttonWithType:UIButtonTypeCustom method of UIButton to create a custom type of button.
[0074] (2) Set the button title and properties: Set the title text, text color, and font for the button respectively, and adjust the size of the text label to fit the text content.
[0075] (3) Calculate and set the border (frame) of the button: Set the width of the border to the text display width plus twice the NAV_BAR_ITEM_CONTENT_INSETS_SPACE to ensure there is an appropriate spacing between the text on the button and the left and right margins of the button, forming a hot zone. For example, the height of the button is fixed at 40 points to ensure sufficient vertical click area.
[0076] The button created by the above method can ensure a consistent spacing between the button content and the edge, whether based on an image or text, and at the same time provides an additional click hot zone, improving the user's interaction experience.
[0077] In some embodiments, the method further includes:
[0078] Provide a creation control for adding a custom button to the navigation bar, and the creation control is bound with a click event;
[0079] In response to the click event on the creation control, generate a creation instruction for the custom button.
[0080] For example, the following third code example can be used to implement the binding of the click event:
[0081]
[0082]
[0083] Among them, creation controls for adding custom buttons to the navigation bar can be provided, and click events can be bound to these creation controls. This process allows developers to dynamically generate custom buttons through interface interaction and add them to the navigation bar. These creation controls can be any clickable element in the user interface, such as buttons, icons, or other interactive elements.
[0084] For example, in the embodiments of this application, these creation controls are created through the programming method of the third code example and can be directly operated in the code, mainly including the following steps:
[0085] (1) Creation controls and binding click events: In the embodiments of this application, the process of creating controls involves instantiating button objects and binding click events to these button objects, for example, by adding one or more click event listeners to the button objects. When the user clicks the button, a predefined action will be triggered.
[0086] (2) Generating creation instructions for custom buttons: In response to the click event of the creation controls, creation instructions for custom buttons are generated. These instructions contain the attribute information of the buttons, such as title, icon, font, color, etc., and the position (left or right) where the button should be placed on the navigation bar.
[0087] (3) Implementing the binding of click events: As shown in the third code example above, the addNavBarItem method demonstrates how to add click events to two button objects, closeBtn and saveBtn, respectively. Among them, self represents the target object of the event, @selector(closeClick:) and @selector(saveClick:) represent the click event handling functions of the close and save buttons respectively, and UIControlEventTouchUpInside represents the trigger event when the button is touched and released.
[0088] (4) Adding custom buttons to the navigation bar: After the button objects are created and click events are bound, the initWithCustomView: method is used to convert these button objects into UIBarButtonItem objects, and then they are set as the left and right buttons of the navigation bar respectively. In this way, when the user clicks these buttons, the corresponding event handling functions, such as closing the page or saving data, will be executed.
[0089] In this way, developers can flexibly add various custom buttons to the navigation bar and implement the interactive functions of the buttons by binding click events. This method not only improves the interactivity of the application but also makes the design of the navigation bar more flexible and personalized. By providing the creation of controls and binding click events in the embodiments of this application, the process of adding custom buttons to the navigation bar becomes more intuitive and dynamic, while maintaining the clarity and easy management of the code.
[0090] In some embodiments, the loop traverses the parent view of the navigation bar buttons under the navigation bar classification to obtain the layout margin attribute value of the parent view, including:
[0091] Traverse and find the navigation bar button item objects for displaying navigation bar buttons under the navigation bar classification;
[0092] Based on the navigation bar button item object, obtain the navigation bar content view of the parent view of the navigation bar button;
[0093] According to the navigation bar content view, obtain the layout margin attribute value of the parent view.
[0094] First, traverse and find the navigation bar button item objects under the navigation bar classification. For example, the program initializes a traversal process, usually through iteration or recursion, for a specific navigation bar classification (such as the top navigation bar, side navigation bar, etc.). During the traversal, the program identifies and locates all the item objects for displaying navigation bar buttons under this classification. These item objects may exist in the form of arrays, lists, or other data structures, and each object represents a specific navigation bar button or button group. For example, in the classification of the navigation bar, all possible view objects containing navigation bar buttons can be traversed programmatically, which usually involves checking whether each sub-view belongs to the navigation bar button item object, and these objects are responsible for displaying the buttons on the navigation bar.
[0095] Then, based on the navigation bar button item object, obtain the navigation bar content view of the parent view of the navigation bar button. For example, after finding each navigation bar button item object, the parent view of the button can be further obtained. In iOS development, the parent view usually contains the layout and display information of the sub-views (such as buttons). However, the directly obtained parent view may be a broader container, and the view specifically used for displaying the navigation bar content, that is, the navigation bar content view, can be located from the parent view. The navigation bar content view usually contains the layout information of all elements such as buttons and titles in the navigation bar.
[0096] Then, based on the navigation bar content view, obtain the layout margin property value of the parent view. After obtaining the navigation bar content view, its layoutMargins property can be accessed, which is a UIEdgeInsets structure that defines the spacing between the edges of the view and the edges of the parent view. In particular, the left and right properties represent the distances between the left and right sides of the content view and the edges of the parent view, respectively.
[0097] Step 120: Adjust the border of the navigation bar button according to the layout margin property value of the parent view to achieve a target spacing between the navigation bar button and the screen edge of the terminal device.
[0098] For example, based on the layout margin property value of the parent view and the target spacing (such as 16 units), adjust the border (frame) of the navigation bar button so that the spacing between the navigation bar button and the screen edge of the terminal device can be maintained at the target spacing (such as 16 units).
[0099] In some embodiments, the layout margin property value includes the left margin value and / or the right margin value of the layout margin of the parent view;
[0100] The adjusting the border of the navigation bar button according to the layout margin property value of the parent view includes:
[0101] Calculate a spacing adjustment parameter for the navigation bar button according to the left margin value and / or the right margin value of the layout margin of the parent view. The spacing adjustment parameter is an adjustment value required for the left button in the navigation bar button to maintain a target spacing from the screen edge of the terminal device and / or an adjustment value required for the right button to maintain a target spacing from the screen edge of the terminal device;
[0102] Adjust the border of the left button and / or the border of the right button according to the spacing adjustment parameter.
[0103] For example, the left margin value refers to the spatial distance between the left side of the parent view and the screen edge of the terminal device. This value determines how far the left boundary of the parent view is from the screen edge.
[0104] For example, the right margin value refers to the spatial distance between the right side of the parent view and the screen edge of the terminal device. This value determines how far the right boundary of the parent view is from the screen edge.
[0105] For example, the left button spacing adjustment parameter: Based on the left margin value of the parent view, an adjustment value is calculated to ensure that the left buttons (such as the back button or menu button) in the navigation bar maintain a preset target spacing from the left edge of the terminal device screen. If the left margin of the parent view is small, it may be necessary to increase the border width of the left button or move the button to the left to maintain the target spacing; conversely, if the left margin is large, it may be necessary to reduce the border width or move the button to the right.
[0106] For example, the right button spacing adjustment parameter: Based on the right margin value of the parent view, an adjustment value is calculated to ensure that the right buttons (such as the settings button or more options button) in the navigation bar maintain a target spacing from the right edge of the terminal device screen. The adjustment logic is similar to that of the left button, but in the opposite direction.
[0107] For example, according to the calculated left button spacing adjustment parameter, the border of the left button is adjusted accordingly, which may include changing the border width, adjusting the position of the button in the parent view, or both.
[0108] For example, according to the right button spacing adjustment parameter, the border of the right button is adjusted to ensure that it meets the target spacing requirements.
[0109] Through the above adjustment process, it can be ensured that the navigation bar buttons maintain a consistent visual spacing from the screen edge under different screen sizes and different parent view margin settings, improving the overall aesthetics and user experience of the user interface. At the same time, this dynamic adjustment mechanism also enables the application to better adapt to the layout requirements of different terminal devices and user interfaces.
[0110] In some embodiments, calculating the spacing adjustment parameter of the navigation bar button according to the left margin value and / or right margin value of the layout margin of the parent view includes:
[0111] According to the left margin value and / or right margin value of the layout margin of the parent view, and the target spacing, calculate the first target adjustment position of the left button and / or the second target adjustment position of the right button;
[0112] The first target adjustment position is used to make the left button maintain a target spacing from the left screen edge of the terminal device and make the button content of the left button maintain a preset spacing from the left margin of the parent view;
[0113] The second target adjustment position is used to make the right button maintain a target spacing from the right screen edge of the terminal device and make the button content of the right button maintain a preset spacing from the right margin of the parent view;
[0114] The target spacing is greater than the preset spacing.
[0115] For example, calculate the first target adjustment position of the left button. Based on the left margin value of the parent view and the target spacing, calculate the first target adjustment position at which the left button should be from the left edge of the screen, so that the left button can be adjusted based on the first target adjustment position until the distance between its outer edge and the screen edge is equal to the target spacing. At the same time, the adjustment process also needs to ensure that the content (such as an icon or text) of the left button does not get too close to the left edge of the parent view, that is, a preset spacing needs to be maintained. Therefore, when calculating the first target adjustment position, both the target spacing and the preset spacing need to be considered.
[0116] For example, calculate the second target adjustment position of the right button. Based on the right margin value of the parent view and the target spacing, calculate the second target adjustment position at which the right button should be from the right edge of the screen, so that the right button can be adjusted based on the second target adjustment position until the distance between its outer edge and the screen edge is equal to the target spacing, while maintaining the preset spacing between the button content and the right edge of the parent view.
[0117] For example, according to the first target adjustment position and / or the second target adjustment position calculated above, the spacing adjustment parameters of the navigation bar button can be determined. These parameters may include the displacement amount of the button, the size adjustment amount, etc., which are used to guide how to adjust the position and size of the button to meet the requirements of the target spacing and the preset spacing.
[0118] In some embodiments, calculating the spacing adjustment parameters of the navigation bar button according to the left margin value and / or the right margin value of the layout margin of the parent view includes:
[0119] Obtain the screen width of the terminal device, where the screen width is determined based on the device model of the terminal device;
[0120] Calculate the spacing adjustment parameters of the navigation bar button according to the screen width, the left margin value and / or the right margin value of the layout margin of the parent view.
[0121] First, the screen width of the terminal device needs to be obtained. The screen width is determined according to the screen size of different device models, because different devices may have different screen resolutions and sizes. The screen width can be obtained through the device's system API or related frameworks, usually a value in pixels (px) or density-independent pixels (dp).
[0122] Then, consider the layout margins of the parent view. The layout margins of the parent view define the space between the parent view and the edges of the terminal device screen. When calculating the spacing adjustment parameters for the navigation bar buttons, these margin values need to be considered to ensure that the positions of the buttons do not exceed the boundaries of the parent view. The left margin value and the right margin value respectively represent the distances between the left and right sides of the parent view and the screen edges.
[0123] Then, calculate the spacing adjustment parameters. Using the screen width and the layout margin values of the parent view, the spacing adjustment parameters for the navigation bar buttons can be calculated. These parameters will guide how to adjust the positions of the buttons to ensure that they maintain a consistent spacing from the screen edges. The spacing adjustment parameters can include the width of the buttons, the spacing between the buttons, the distance of the buttons from the edges of the parent view, etc.
[0124] In some embodiments, adjusting the border of the navigation bar button according to the layout margin attribute value of the parent view includes:
[0125] Adjust the border of the parent view of the navigation bar button according to the layout margin attribute value of the parent view.
[0126] Among them, adjusting the border of the navigation bar button to achieve consistency with the target spacing of the screen edge involves directly adjusting the border of the parent view of the navigation bar button.
[0127] For example, in the iOS system, layoutMargins is a property of UIView, which defines the space between the view content and its boundaries. For the parent view of the navigation bar button, these margin values determine the distance between the button and the edge of the navigation bar.
[0128] For example, according to the layout margin attribute value of the parent view, the border of the parent view of the navigation bar button can be adjusted. This usually involves modifying the frame (border) property of the parent view to ensure that the button is correctly aligned with its content and maintains an appropriate spacing from the screen edge. First, according to the target spacing (such as the globally macro-defined NAV_ITEM_SCREEN_SPACING) and the preset spacing (such as
[0129] Based on the NAV_BAR_CONTENT_SCREEN_SPACING, calculate the value that needs to be adjusted. This value will be used to determine the new position of the parent view's border. Then, apply the calculated adjustment value to the frame of the parent view. If the goal is to keep a 16-unit spacing between the navigation bar button and the screen edge, and the preset spacing is 8 units, then the x coordinate of the frame of the parent view needs to be adjusted inwards or outwards to achieve this goal. When adjusting the parent view's border, the screen width of the terminal device also needs to be considered. This is because different devices may have different screen sizes, and the adjustment value needs to be calculated based on the screen width to ensure the expected layout effect on all devices. After completing the border adjustment, trigger a layout update to ensure that the navigation bar button is arranged according to the new border layout.
[0130] In some embodiments, the method further includes:
[0131] Recursively traverse all subviews under the navigation bar category to obtain the current border of the navigation bar content view of the parent view of the navigation bar button;
[0132] Based on the current border of the navigation bar content view and the target spacing, calculate the position information and size information of the border of the navigation bar content view;
[0133] Based on the position information and size information, update the border of the navigation bar button.
[0134] For example, the border of the navigation bar button can be updated through the following fourth code example:
[0135]
[0136]
[0137] Among them, for the above fourth code example, it mainly includes the following steps:
[0138] (1) Recursively traverse subviews: Through the nt_setupSubviewWithLevel: method, recursively traverse all subviews of the UINavigationBar object. This method allows starting from the deepest subview and traversing layer by layer up to the parent view to locate the parent view of the navigation bar button.
[0139] (2) Obtain the navigation bar content view: During the traversal process, when an object of type
[0140] _UINavigationBarContentView is recognized, obtain its current frame (border). This current frame defines the current position and size of the navigation bar content view on the screen.
[0141] (3) Calculate the new border position information and size information: Based on the current border of the navigation bar content view and the preset target spacing (such as NAV_BAR_CONTENT_SCREEN_SPACING), calculate the new border position information (x - coordinate) and size information (width). This includes adjusting the x - coordinate to achieve the target spacing between the left button and the left edge of the screen, and adjusting the width to achieve the target spacing between the right button and the right edge of the screen.
[0142] (4) Update the border of the navigation bar button: Use the calculated new position information and size information to update the frame of the navigation bar content view. This involves modifying the origin.x (horizontal position) and size.width (width) of the frame to ensure that the navigation bar button maintains a consistent spacing from the screen edge.
[0143] Among them, after updating the frame of the navigation bar content view, these changes will be applied to the navigation bar layout to ensure that the navigation bar buttons are laid out according to the new border. By this method, regardless of the device or screen size, the navigation bar buttons can maintain a consistent spacing from the screen edge, improving the interface consistency and user experience of the application.
[0144] Step 130, display the navigation bar at the target spacing according to the target spacing.
[0145] For example, the updated navigation bar buttons will be re - laid out and displayed on the screen. In the business logic, when setting the navigation bar buttons, the initWithCustomView method of the navigation bar button item (UIBarButtonItem) can be used to use the custom button as the left button and / or right button of the navigation bar. These custom left buttons and / or right buttons have considered the preset spacing (such as 8 units) from the screen edge when created, ensuring that the spacing between the navigation bar buttons and the screen edge remains consistent on different device models or different systems, achieving aesthetics and consistency.
[0146] In some embodiments, the displaying the navigation bar at the target spacing according to the target spacing includes:
[0147] Layout the navigation bar buttons using the adjusted border of the parent view according to the target spacing;
[0148] Display the navigation bar at the target spacing, and the navigation bar buttons in the navigation bar maintain the target spacing from the screen edge of the terminal device.
[0149] For example, after calculating and applying the navigation bar content view of the parent view (such as
[0150] After the border of the _UINavigationBarContentView is adjusted, use this new border information to layout the navigation bar buttons. This means that the position and size of the navigation bar buttons will be set according to the adjusted parent view border to ensure that the spacing between the buttons and the screen edge meets the design requirements. After completing the layout of the navigation bar buttons, the navigation bar will be displayed on the screen. In this state, the left button and / or the right side in the navigation bar should maintain a consistent target spacing from the screen edge of the terminal device.
[0151] As Figure 2 shown, the navigation bar 20 at the target spacing L is displayed on the screen 10 of the terminal device, and the navigation bar buttons 21 in the navigation bar 20 maintain the target spacing L from the screen edge of the terminal device. Specifically, the left button 211 in the navigation bar 20 maintains the target spacing L from the left screen edge 11 of the terminal device, and the right button 212 in the navigation bar 20 maintains the target spacing L from the right screen edge 12 of the terminal device.
[0152] To further illustrate the specific operations of the navigation bar view adjustment method in the embodiments of the present application, the following is a detailed description through specific embodiments:
[0153] (1) Declaration of macro definitions: Declare three global macro definitions in the code to facilitate subsequent spacing adjustment and maintenance work:
[0154] NAV_ITEM_SCREEN_SPACING: For example, its value is set to 16. The value of this macro definition represents the target spacing that the navigation bar buttons (whether left or right buttons) are expected to maintain from the screen edge.
[0155] NAV_BAR_CONTENT_SCREEN_SPACING: For example, its value is set to 8. The value of this macro definition represents the preset spacing that the navigation bar buttons (whether left or right buttons) actually maintain from the screen edge after adopting the unified processing method. This allows for a spacing of (NAV_ITEM_SCREEN_SPACING - NAV_BAR_CONTENT_SCREEN_SPACING) on both sides as a hot zone, that is, the sensitive area for user interaction.
[0156] NAV_BAR_ITEM_CONTENT_INSETS_SPACE: The calculated value is NAV_ITEM_SCREEN_SPACING - NAV_BAR_CONTENT_SCREEN_SPACING, and this value is used for the left and right spacing reserved by the business layer when generating buttons to ensure that the buttons have a sufficient hot zone range.
[0157] (2) Creation of navigation bar classification: Create a classification of the navigation bar (UINavigationBar) named UINavigationBar+ZZNavigationBarBarItemFixSpace. In this classification, use method swizzling technology to override the layoutSubviews method for custom adjustments during view layout.
[0158] (3) Analysis of view hierarchy: Through view hierarchy analysis, identify the navigation bar button item (_UIButtonBarStackView) object, which is the direct container for displaying the left and right buttons of the navigation bar. Assume the navigation bar button item (_UIButtonBarStackView) object is named barStackView, and its subviews are the navigation bar button views set by the business layer for different pages. The parent view of barStackView is the navigation bar content view (_UINavigationBarContentView) object, assumed to be named barContentView.
[0159] (4) Adjustment of navigation bar content view: In the layoutSubviews method, locate the navigation bar content view (_UINavigationBarContentView) by traversing the subviews under the navigation bar (UINavigationBar) classification. Then, according to the layoutMargins property of barContentView, adjust the x coordinate and width of its frame so that the distance between barStackView and the screen edge remains 16 unit lengths.
[0160] (5) Encapsulation of business layer button generation method: In the business layer, encapsulate the method for generating common navigation bar buttons. For example, for an icon with a size of 24 unit lengths, create a button with a size of 40*40 unit lengths and 8 unit lengths of spacing on both the left and right. Through the initWithCustomView method of initializing a custom view, use this button as the custom view of the navigation bar button item (UIBarButtonItem), thus becoming a subview of the navigation bar button item object (barStackView).
[0161] Through the above steps, it is ensured that when the entire application uses the system navigation bar, the spacing between the left and right buttons and the screen edge remains consistent, improving the aesthetics of the interface and the user interaction experience.
[0162] Any combination of the above technical solutions can form an optional embodiment of this application, which will not be elaborated here one by one.
[0163] In the embodiments of the present application, a navigation bar classification is created, and the parent views of the navigation bar buttons under the navigation bar classification are traversed in a loop to obtain the layout margin attribute values of the parent views; according to the layout margin attribute values of the parent views, the borders of the navigation bar buttons are adjusted to achieve the target spacing between the navigation bar buttons and the screen edge of the terminal device; according to the target spacing, the navigation bar at the target spacing is displayed. In the embodiments of the present application, by creating a navigation bar classification, it provides convenience for expanding and modifying the functions of the navigation bar, and at the same time avoids directly modifying the underlying system code, ensuring the stability and security of the system; by traversing the parent views of the navigation bar buttons, it accurately locates the view hierarchy responsible for displaying the navigation bar buttons, providing an accurate target object for subsequent spacing adjustment; by obtaining the layout margin attribute values of the parent views and dynamically adjusting the borders of the navigation bar buttons according to the layout margin attribute values, it ensures that the spacing between the navigation bar buttons and the screen edge remains consistent on different models and different system versions; according to the target spacing, the navigation bar is displayed, making the application interface maintain consistent aesthetics and consistency in different devices and system environments, and reducing the development difficulty and maintenance cost.
[0164] To facilitate better implementation of the view adjustment method of the navigation bar in the embodiments of the present application, the embodiments of the present application also provide a view adjustment device for the navigation bar. Please refer to Figure 3 , Figure 3 which is a schematic structural diagram of the view adjustment device for the navigation bar provided in the embodiments of the present application. The view adjustment device 200 for the navigation bar may include:
[0165] A processing unit 210, configured to create a navigation bar classification and traverse the parent views of the navigation bar buttons under the navigation bar classification in a loop to obtain the layout margin attribute values of the parent views;
[0166] An adjustment unit 220, configured to adjust the borders of the navigation bar buttons according to the layout margin attribute values of the parent views to achieve the target spacing between the navigation bar buttons and the screen edge of the terminal device;
[0167] A display unit 230, configured to display the navigation bar at the target spacing according to the target spacing.
[0168] In some embodiments, the layout margin attribute values include the left margin value and / or the right margin value of the layout margin of the parent view;
[0169] The adjustment unit 220 may be configured to:
[0170] Calculate the spacing adjustment parameter of the navigation bar button according to the left margin value and / or the right margin value of the layout margin of the parent view, where the spacing adjustment parameter is the adjustment value required for the left button in the navigation bar buttons to maintain a target spacing from the screen edge of the terminal device, and / or the adjustment value required for the right button to maintain a target spacing from the screen edge of the terminal device;
[0171] Adjust the border of the left button and / or the border of the right button according to the spacing adjustment parameter.
[0172] In some embodiments, when calculating the spacing adjustment parameter of the navigation bar button according to the left margin value and / or the right margin value of the layout margin of the parent view, the adjustment unit 220 can be used for:
[0173] Calculate the first target adjustment position of the left button and / or the second target adjustment position of the right button according to the left margin value and / or the right margin value of the layout margin of the parent view, and the target spacing;
[0174] The first target adjustment position is used to make the left button maintain a target spacing from the left screen edge of the terminal device, and make the button content of the left button maintain a preset spacing from the left margin of the parent view;
[0175] The second target adjustment position is used for the right button to maintain a target spacing from the right screen edge of the terminal device, and make the button content of the right button maintain a preset spacing from the right margin of the parent view;
[0176] The target spacing is greater than the preset spacing.
[0177] In some embodiments, when calculating the spacing adjustment parameter of the navigation bar button according to the left margin value and / or the right margin value of the layout margin of the parent view, the adjustment unit 220 can be used for:
[0178] Obtain the screen width of the terminal device, where the screen width is determined based on the device model of the terminal device;
[0179] Calculate the spacing adjustment parameter of the navigation bar button according to the screen width, the left margin value and / or the right margin value of the layout margin of the parent view.
[0180] In some embodiments, the processing unit 210 can be used for:
[0181] Traverse and find the navigation bar button item object for displaying the navigation bar button under the navigation bar classification;
[0182] Based on the navigation bar button item object, obtain the navigation bar content view of the parent view of the navigation bar button;
[0183] According to the navigation bar content view, obtain the layout margin attribute value of the parent view.
[0184] In some embodiments, the processing unit 210 may further be configured to:
[0185] Set a target spacing between the navigation bar button and the screen edge;
[0186] Set a preset spacing between the navigation bar button and the screen edge, where the preset spacing is half of the target spacing;
[0187] According to the difference between the target spacing and the preset spacing, set the hot zone range of the navigation bar button.
[0188] In some embodiments, the processing unit 210 may further be configured to:
[0189] In response to a creation instruction for a custom button, create a custom button according to the hot zone range.
[0190] In some embodiments, the creating a custom button according to the hot zone range in response to a creation instruction for a custom button includes:
[0191] Receive a creation instruction for a custom button, where the creation instruction carries button title text information and / or button icon information of the custom button;
[0192] According to the hot zone range, and the button title text information and / or the button icon information, create a custom button with the preset spacing.
[0193] In some embodiments, the processing unit 210 may further be configured to:
[0194] Provide a creation control for adding a custom button to the navigation bar, where the creation control is bound with a click event;
[0195] In response to a click event for the creation control, generate a creation instruction for a custom button.
[0196] In some embodiments, the adjustment unit 220 may be configured to:
[0197] According to the layout margin attribute value of the parent view, adjust the border of the parent view of the navigation bar button.
[0198] In some embodiments, the display unit 230 may be configured to:
[0199] Layout the navigation bar buttons using the adjusted border of the parent view according to the target spacing;
[0200] Display the navigation bar at the target spacing, with the navigation bar buttons in the navigation bar maintaining the target spacing from the screen edge of the terminal device.
[0201] In some embodiments, the adjustment unit 220 may also be used for:
[0202] Recursively traverse all child views under the navigation bar classification to obtain the current border of the navigation bar content view of the parent view of the navigation bar buttons;
[0203] Calculate the position information and size information of the border of the navigation bar content view based on the current border of the navigation bar content view and the target spacing;
[0204] Update the border of the navigation bar buttons according to the position information and size information.
[0205] Each unit in the above view adjustment device of the navigation bar can be implemented in whole or in part by software, hardware, and their combination. The above units can be embedded in the processor of the computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to the above units.
[0206] The view adjustment device 200 of the navigation bar can be integrated in a terminal or server with a memory and equipped with a processor and having computing power, or the view adjustment device 200 of the navigation bar is the terminal or server.
[0207] Optionally, the present application also provides a computer device, including a memory and a processor. A computer program is stored in the memory, and when the processor executes the computer program, the steps in the above method embodiments are implemented.
[0208] Figure 4 This is a schematic structural diagram of the computer device provided by the embodiments of the present application. The computer device can be a terminal or a server. As Figure 4 shown, the computer device 300 may include: a communication interface 301, a memory 302, a processor 303, and a communication bus 304. The communication interface 301, the memory 302, and the processor 303 communicate with each other through the communication bus 304. The communication interface 301 is used for the computer device 300 to communicate with external devices. The memory 302 can be used to store software programs and modules, and the processor 303 runs the software programs and modules stored in the memory 302, such as the software programs for the corresponding operations in the foregoing method embodiments.
[0209] Optionally, the processor 303 may call software programs and modules stored in the memory 302 to perform the following operations:
[0210] Create a navigation bar classification, and loop through the parent views of the navigation bar buttons under the navigation bar classification to obtain the layout margin attribute values of the parent views; according to the layout margin attribute values of the parent views, adjust the borders of the navigation bar buttons to achieve a target spacing between the navigation bar buttons and the screen edge of the terminal device; according to the target spacing, display the navigation bar at the target spacing.
[0211] The present application also provides a computer-readable storage medium for storing a computer program. The computer-readable storage medium can be applied to a computer device, and the computer program enables the computer device to execute the corresponding processes in the view adjustment method of the navigation bar in the embodiments of the present application. For the sake of brevity, it will not be elaborated here.
[0212] Schematic diagram of the storage medium provided by the embodiments of the present application, as Figure 5 shown, describes a program product 400 for implementing the above method according to an exemplary embodiment of the present application. It may be a portable compact disc read-only memory (CDROM) and includes program code, and can run on a computer device, such as a mobile phone. However, the program product of the present application is not limited to this. In the present application, the readable storage medium may be any tangible medium that contains or stores a program, and the program can be used by or in combination with an instruction execution system, apparatus, or device.
[0213] The present application also provides a computer program product, which includes computer instructions stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, enabling the computer device to execute the corresponding processes in the view adjustment method of the navigation bar in the embodiments of the present application. For the sake of brevity, it will not be elaborated here.
[0214] The present application also provides a computer program, which includes computer instructions stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, enabling the computer device to execute the corresponding processes in the view adjustment method of the navigation bar in the present application. For the sake of brevity, it will not be elaborated here.
[0215] It should be understood that the processor of the present application may be an integrated circuit chip with signal processing capabilities. In the implementation process, the steps of the above method embodiments can be completed by the integrated logic circuit in the hardware of the processor or instructions in the form of software. The above processor may be a general-purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as being executed and completed by a hardware decoding processor, or executed and completed by a combination of hardware and software modules in the decoding processor. The software module may be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. This storage medium is located in the memory, and the processor reads the information in the memory and combines its hardware to complete the steps of the above method.
[0216] It can be understood that the memory in the embodiments of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable ROM (PROM), an erasable programmable ROM (EPROM), an electrically erasable programmable ROM (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchlink DRAM (SLDRAM), and direct rambus RAM (DR RAM). It should be noted that the memory of the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0217] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, or by a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.
[0218] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices, and units described above can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated herein.
[0219] In the embodiments of the present application, the term "module" or "unit" refers to a computer program with a predetermined function or a part of a computer program, which works together with other relevant parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as a processing circuit or a memory), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of an overall module or unit that includes the function of that module or unit.
[0220] In several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of the devices or units can be in electrical, mechanical, or other forms.
[0221] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place, or they can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0222] In addition, each functional unit in the present application can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0223] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art or a part of this technical solution can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer or a server) to execute all or part of the steps of the methods described in various embodiments of the present application. The foregoing storage medium includes: various media such as a USB flash drive, a mobile hard disk, a ROM, a RAM, a magnetic disk, or an optical disc that can store program codes.
[0224] As described above, it is only the specific implementation manner of the present application. However, the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present application can easily think of changes or substitutions, which should all be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A method for adjusting the view of a navigation bar, characterized in that: The method comprises: Create a navigation bar category, and loop through the parent views of the navigation bar buttons under the navigation bar category to obtain the layout margin attribute value of the parent view; Adjusting the border of the navigation bar button according to the layout margin attribute value of the parent view to achieve a target spacing between the navigation bar button and the screen edge of the terminal device; According to the target distance, a navigation bar under the target distance is displayed.
2. The method for adjusting the view of the navigation bar according to claim 1, characterized in that: The layout margin attribute value includes a left margin value and / or a right margin value of the layout margin of the parent view; The adjusting the border of the navigation bar button according to the layout margin attribute value of the parent view includes: Calculate, according to the left margin value and / or the right margin value of the layout margin of the parent view, a spacing adjustment parameter of the navigation bar buttons, wherein the spacing adjustment parameter is an adjustment value required for maintaining a target spacing between a left button of the navigation bar buttons and a screen edge of a terminal device, and / or an adjustment value required for maintaining a target spacing between a right button and a screen edge of the terminal device; The border of the left button and / or the border of the right button are adjusted according to the spacing adjustment parameter.
3. The method for adjusting the view of the navigation bar according to claim 2, characterized in that: The calculating the spacing adjustment parameter of the navigation bar button according to the left margin value and / or the right margin value of the layout margin of the parent view includes: Calculate a first target adjustment position of the left button and / or a second target adjustment position of the right button according to a left margin value and / or a right margin value of the layout margin of the parent view and the target spacing; The first target adjustment position is used to keep the target spacing between the left button and the left screen edge of the terminal device, and to keep the button content of the left button and the left margin of the parent view at a preset spacing; The second target adjustment position is used to maintain a target spacing between the right button and the right screen edge of the terminal device, and to maintain a preset spacing between the button content of the right button and the right margin of the parent view; The target distance is greater than the preset distance.
4. The method for adjusting the view of the navigation bar according to claim 2, wherein: The calculating the spacing adjustment parameter of the navigation bar button according to the left margin value and / or the right margin value of the layout margin of the parent view includes: Acquire a screen width of the terminal device, where the screen width is determined based on a device model of the terminal device; The spacing adjustment parameters of the navigation bar buttons are calculated according to the screen width and the left margin value and / or the right margin value of the layout margin of the parent view.
5. The method for adjusting the view of the navigation bar according to claim 1, characterized in that: The loop traverses the parent view of the navigation bar button under the navigation bar category to obtain the layout margin attribute value of the parent view, including: Traverse and search for navigation bar button item objects under the navigation bar category for displaying navigation bar buttons; Based on the navigation bar button item object, obtain the navigation bar content view of the parent view of the navigation bar button; According to the navigation bar content view, obtain the layout margin attribute value of the parent view.
6. The method for adjusting the view of the navigation bar according to claim 1, characterized in that: The method further comprises: Set the target distance between the navigation bar button and the edge of the screen; Setting a preset distance between the navigation bar button and the screen edge, wherein the preset distance is half of the target distance; The hot zone range of the navigation bar button is set according to the difference between the target distance and the preset distance.
7. A navigation bar view adjustment device, characterized in that: The device comprises: A processing unit, used to create a navigation bar category, and loop through the parent views of the navigation bar buttons under the navigation bar category to obtain a layout margin attribute value of the parent view; an adjusting unit, configured to adjust the border of the navigation bar button according to the layout margin attribute value of the parent view, so as to achieve a target spacing between the navigation bar button and the screen edge of the terminal device; The display unit is used to display a navigation bar under the target distance according to the target distance.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is suitable for being loaded by a processor to execute the view adjustment method of the navigation bar according to any one of claims 1 to 6.
9. A computer device, characterized in that: The computer device includes a processor and a memory, wherein a computer program is stored in the memory, and the processor is used to execute the navigation bar view adjustment method according to any one of claims 1 to 6 by calling the computer program stored in the memory.
10. A computer program product comprising computer instructions, characterized in that When the computer instructions are executed by a processor, the method for adjusting the view of the navigation bar described in any one of claims 1 to 6 is implemented.