简体   繁体   English

约束无法正常工作

[英]Constraints Not Working Properly

I have fiddled with the constraints for a while and for some reason on a view bigger than the view in the main storyboard looks awful. 一段时间以来,我一直在摆弄约束,出于某种原因,它的视图比主故事板上的视图大。 Right now it's on reset to suggested constraints. 现在,它已重置为建议的约束。 Those are my constraints below, I'm not sure what's going on. 这些是我下面的约束,我不确定发生了什么。 Is there something wrong with my Xcode or am I doing something wrong? 我的Xcode出问题了吗?还是我做错了什么?

在此处输入图片说明

在此处输入图片说明

The button stretches because you pinned it to the top and to the bottom. 因为您将按钮固定在顶部和底部,所以按钮会拉伸。 So on a larger screen the distance from the top and the bottom stays the same which means that the button is stretched. 因此,在较大的屏幕上,距顶部和底部的距离保持不变,这意味着按钮已拉伸。

Keeping the size of the button 保持按钮的大小

The keep the size of the bottom an center is vertically und horizontally you have to give a width and a height constraint and a centerY and centerX constraint: 保持底部中心的大小垂直和水平,您必须给出宽度高度约束以及centerYcenterX约束:

在此处输入图片说明

Keeping the aspect ratio of the button 保持按钮的长宽比

EDIT : This is a cleaner solution suggested by Sega-Zero : 编辑 :这是由世嘉零建议的更清洁的解决方案:

To scale the button according to the screen size but keep its aspect ratio you have to set an equal width constraint (with a multiplier) between button an its superview, an aspect ratio constraint and centerY and centerX constraints: 要根据屏幕尺寸缩放按钮但保持其长宽比,您必须在按钮及其上级长宽比约束以及centerYcenterX约束之间设置相等的宽度约束(使用乘数):

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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