简体   繁体   中英

iOS auto-layout unsatisfied constraints due to 0 sized container view

I put a view inside a container view with constraints:

@"H:|-15-[myView]-15-|"

And when the container view's created, its size is zero, and the code crashes, since it cannot satisfy the constraint that both left/right edges are 15 points apart from the left/right edges of zero sized container.

Is there a way to have some priority of this constraints, or is there a better way to do this? Assume the container cannot have a frame when created with the subview.

Thanks!

Yes, you can set priorities to constraints.

You have to add "@value" after the constraint constant like so:

@"H:|-15@750-[myView]-15-|"

Priority level . Constraints have a priority level. Constraints with higher priority levels are satisfied before constraints with lower priority levels. The default priority level is required (NSLayoutPriorityRequired), which means that the constraint must be satisfied exactly. The layout system gets as close as it can to satisfying an optional constraint, even if it cannot completely achieve it. Priority levels allow you to express useful conditional behavior. For example, they are used to express that some controls should always be sized to fit their contents, unless something more important should take precedence. For more information about priority levels, see NSLayoutPriority.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM