- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作键盘。我在 View 中有 9 个按钮:宽度和高度 <= 75。在 iPhone 5 上完美运行。但是 iPhone 4 的按钮被拉长了,尺寸仍然是 75。谁能帮帮我?
最佳答案
问题是您告诉 View (按钮)的高度或宽度 >= 75,这意味着您的布局不明确(有人已经提到过这一点)——您可以通过检查 View 的 hasAmbiguousLayout 属性来检查这一点.它可能无法在 iPhone 5 上正常工作,或者碰巧当您运行它时,自动布局已经找到了您正在寻找的解决方案,因此它似乎可以正常工作。运行它足够多次,最终您可能会得到不需要的布局。啊自动布局的乐趣。无论如何,这个问题的一个解决方案是设置一个按钮的高度和宽度,然后告诉所有其他按钮跟随套件。视觉格式语言指南有一个这样的例子,但我会告诉你我的意思。
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[button1(75)[button2(==button1)[button3(==button1)]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(button1, button2, button3)]];
然后做一些类似的事情来垂直放置它们。当自动布局运行时,它应该为它们找到正确的布局。下一个问题是如何使用它。如果您在 UIView 的子类中完成所有这些工作,然后继续将 View 宽度设置为 400 pt 之类的疯狂宽度,那么自动布局将中断 - 在这种情况下,因为我们固定在左侧和右侧。要解决这个问题,我可能会删除最后一个 |并且不将 button3 的右侧固定到父 View 的右侧。
您的另一个选择是使用长格式指定约束。例如
//set button1 width to 75
[self.view addConstraint:[NSLayoutConstraint
constraintWithItem:button1
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:75]];
//set button2 width == button1
[self.view addConstraint:[NSLayoutConstraint
constraintWithItem:button2
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:button1
attribute:NSLayoutAttributeWidth
multiplier:1
constant:0]];
//pin button1 to the left
[self.view addConstraint:[NSLayoutConstraint
constraintWithItem:button1
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1
constant:0]];
//pin button2 to button1
[self.view addConstraint:[NSLayoutConstraint
constraintWithItem:button2
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:button1
attribute:NSLayoutAttributeRight
multiplier:1
constant:0]];
关于iOS 约束 : how to adjust UIButton width and height in a view?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23395386/
我收到此错误如何解决? 我尝试通过安装它然后我也遇到了问题npm install autoprefixer@10.4.5 --save-exact WARNING in ./node_modules/
我有一个 ListView,其中 EditTexts 作为项目。 我已经尝试设置 android:windowSoftInputMode="adjustPan" 和 "adjustResize" li
我有一个 p.value 数据框,每列都有变量名。 我的代码是sapply(pval,p.adjust,method="fdr")。 此代码返回基于每列调整的qvalue,这意味着p基于每列排名然后调
我的自定义图形项目有 (0,-60 60x60) 边界矩形。当我调整坐标时 rect.adjusted(-5,-5,5,5) 新的boundingRect返回(-5,-65,70x70)。我阅读了文档
我有一个 UITableViewController,它嵌入到 TabbarController 中,而 TabbarController 又嵌入到 UINavigationController 中。
我有一个进度条,我正在尝试根据 :after 伪元素的 content 调整父项的高度。运行代码后,您会看到 30% 部分位于 div 内。 有没有办法调整 :after 附加到的元素的高度? 我尝试
我的问题:有没有办法调整 UIPanGestureRecognizer 的“敏感度”,使其“更快”开启,即在移动较少数量的“像素”之后? 我有一个带有 UIImageView 的简单应用程序,以及与此
我在创建我的移动应用程序时使用了以下 config.lua 文件。 构 build 备时,屏幕不会适应 iPhone5。但是,它会在 corona 提供的模拟器上运行时进行调整。 你能告诉我问题是出在
我正在开发一个应用程序,它可以扫描数千个结构副本; ~1 GB 内存。速度很重要。 ParallelScan(_from, _to); //In a new thread 我手动调整线程数
我有一段代码必须在每天的特定时间执行。如果我安排它在每天晚上 9 点执行,那么即使在夏令时切换期间它也必须工作。 可以使用哪个 Java API 来实现这一点? int ONE_DAY = 1000
我想在自定义列表适配器的一个节点中显示一个 ImageView、2 个 TextViews 和一个 Rating Bar 但当我将其裁剪时运行代码 这里是自定义列表的xml代码 Here is the
在我的项目中,我定义了一个 xib 和一个将包含 xib 的 ViewController。 class FeedDetailViewController: UIViewController, Fee
我正在尝试做一个垂直下拉菜单。这是我的代码 .menu li:hover>ul{ position:absolute; display:inline; left:120px; top:
我想在 font-family (font-family:A, B;) 中指定两种不同的字体,但是这两种字体的大小不同。 font-size-adjust 似乎只能在 Firefox 中使用。那么,如
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this q
这个问题已经有答案了: JavaFX BarChart xAxis labels bad positioning (4 个回答) 已关闭 4 年前。 我正在使用 JavaFX 编写一个小直方图。我使用
我有一个非常简单的场景,但我真的坚持了下来,需要你的帮助。 这是我必须做的。 这是一个带有右边框和底边框以及顶部有图像的 div。我必须显示与此相同的文本。为此,我正在使用这样的 Bootstrap
我为此做了一些窥探。有一些解决方案,但我无法正确理解它们。我试图实现旋转矩阵,但我做不到。我创建了一个简单的 fiddle ,点击图像旋转 90 度(不包括我的实现,因为我不明白如何去做)。下面是那个
我想调整 table 标签中的图像,如果在单个 tr 中有四个图像,在第二个 tr
这是我的设置: SKScene 有一个名为 world 的节点 在这个世界上,我附加了另一个节点:车辆 我将三个节点附加到这辆车上;一个 body 和两个轮子 轮子通过指定 anchor 的 SKPh
我是一名优秀的程序员,十分优秀!