← 返回 airbnb 的题目列表UIView Layout Math (Compute Frames From Constraints)
类型:online_judge
Problem: UIView Layout Math (Compute Frames From Constraints)
Given a parent view container size and a set of layout constraints for one or more subviews (e.g., margins to parent edges, fixed width/height, proportional sizing, horizontal/vertical centering, fixed spacing between sibling views, etc.), compute and output the final frame (x, y, width, height) for each subview.
Note: The shared interview note does not include the full constraint set. Use the exact constraints provided by the interviewer and implement a function/procedure that solves for frames accordingly.
What you need to do
Read the parent size W, H
Read any constraint parameters described in the prompt
Output all subview frames
Follow-up
If the view is placed inside a relativeView instead of being positioned in the global/root coordinate system:
How would you modify your computation to convert coordinates into the relativeView's local coordinate system?
Scale
Typically 1 to a few subviews (as specified during the interview)
Parameters are integers/floats
Test cases
(Not provided in the note; construct based on the constraints used in the interview.)
Example
Input
(not specified)
Output
(not specified)