- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
为了说明我的问题,我创建了下图:
红色方 block 周围的黑色边框应该是 iPhone 屏幕。在里面,我们有一个红色的 UIScrollView
,它比屏幕高。事实上,它与 UIWebView
一样高,上面显示为黄色。 UIWebView
是 UIScrollView
的 subview ,禁用滚动。此外,我们有两个蓝色 View ,我喜欢称之为页眉和页脚 View 。它们也是 UIScrollView
的 subview ,但在可滚动边界之外。
我现在的问题是:如何为此配置自动布局约束?
我已经设法使用 code from this answer 检索了 UIWebView
高度然后相应地更新 UIScrollView
的 contentSize
。然而,这并不是一个好的解决方案,因为 UIWebView
的宽度不会对 UIScrollView
的宽度变化使用react。
我还设法像这样设置标题 View 的布局约束(使用 Masonary ):
[headerView makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@-100);
make.left.equalTo(@0);
make.width.equalTo(scrollView.width);
make.height.equalTo(@100);
}];
但是,像这样设置页脚 View 的布局不起作用:
[changeView makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(scrollView.bottom)
make.left.equalTo(@0);
make.width.equalTo(scrollView.width);
make.height.equalTo(@100);
}];
我觉得这不会太难,希望能得到更熟悉自动布局的人的帮助。谢谢!
最佳答案
在视觉格式语言 (VFL) 中,约束是:
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(-100)-[headerView(100)]" options:0 metrics:nil views:views]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[footerView(100)]-(-100)-|" options:0 metrics:nil views:views]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[headerView]|" options:0 metrics:nil views:views]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[footerView]|" options:0 metrics:nil views:views]];
或者,如果您要用 constraintWithItem
调用替换 @"V:[footerView(100)]-(-100)-|"
VFL,它会是:
[footerView addConstraint:[NSLayoutConstraint constraintWithItem:footerView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:100.0]];
[scrollView addConstraint:[NSLayoutConstraint constraintWithItem:footerView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:scrollView
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:100.0]];
我不能说为什么您的 Masonary 实现不起作用,因为我不熟悉它。但我会尝试以上方法之一并确保。
老实说,你描述了设置web View 的高度,我想知道你是设置了web View 的高度约束(好)还是只是调整了frame.size.height
的值(坏的)。但是您还没有分享如何设置 WebView 高度的细节,所以我无法进一步评论。
无论如何,如果您遇到基于约束的问题,有两种有用的诊断技术。如果它仍然不工作,我会在模拟器上运行应用程序,暂停它,然后在 (lldb)
提示符下输入:
po [[UIWindow keyWindow] _autolayoutTrace]
您应该会看到如下内容:
(lldb) po [[UIWindow keyWindow] _autolayoutTrace]
$0 = 0x0715d6e0
*<UIWindow:0x758aae0>
| *<UIView:0x71630f0>
| | *<UIScrollView:0x716a370>
| | | *<HeaderView:0x716b860>
| | | *<FooterView:0x716bbb0>
| | | *<UIWebView:0x716c2b0>
| | | | <_UIWebViewScrollView:0x7176a30>
| | | | | ...
| | | | | <UIWebBrowserView:0x797fe00>
| | | <UIImageView:0x75e1360>
| | | <UIImageView:0x75e2a60>
确保那里没有任何警告。如果一切正常,那么我将在 (lldb)
提示符下使用以下命令:
po [[UIWindow keyWindow] recursiveDescription]
您应该会看到如下内容:
(lldb) po [[UIWindow keyWindow] recursiveDescription]
$1 = 0x071c0ea0 <UIWindow: 0x758aae0; frame = (0 0; 320 568); autoresize = W+H; layer = <UIWindowLayer: 0x758b770>>
| <UIView: 0x71630f0; frame = (0 20; 320 548); autoresize = RM+BM; layer = <CALayer: 0x7163180>>
| | <UIScrollView: 0x716a370; frame = (0 0; 320 548); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x716b1d0>; layer = <CALayer: 0x716ad20>; contentOffset: {0, 16}>
| | | <HeaderView: 0x716b860; frame = (0 -100; 320 100); layer = <CALayer: 0x716b910>>
| | | <FooterView: 0x716bbb0; frame = (0 564; 320 100); layer = <CALayer: 0x716bee0>>
| | | <UIWebView: 0x716c2b0; frame = (0 8; 320 548); layer = <CALayer: 0x716c360>>
| | | | <_UIWebViewScrollView: 0x7176a30; frame = (0 0; 320 548); clipsToBounds = YES; autoresize = H; gestureRecognizers = <NSArray: 0x7177000>; layer = <CALayer: 0x7176c80>; contentOffset: {0, 0}>
| | | | | ...
| | | | | <UIWebBrowserView: 0x797fe00; frame = (0 0; 1024 1754); gestureRecognizers = <NSArray: 0x7173260>; layer = <UIWebLayer: 0x716d7f0>>
| | | | | | ...
| | | <UIImageView: 0x75e1360; frame = (1 540; 318 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x75e2980>>
| | | <UIImageView: 0x75e2a60; frame = (312 32.5; 7 530.5); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x75e2b00>>
查看各种生成的 frame
值,看看发生了什么。这可以帮助您诊断解决方案。您没有为我们提供足够的信息来诊断问题(您告诉我们页脚不起作用,但您没有告诉我们您的约束最终将其放置在哪里)。如果您执行上述命令,您可以准确地确定您的约束最终放置页脚的位置,然后找出如何从那里解决问题。
请注意,您会看到我的 headerView
和 footerView
在这两个列表中显示为 HeaderView
和 FooterView
类而不是 UIView
。在诊断约束问题时,如果关键 View 有自己的类,这将很有用,因此我定义了没有实现的 UIView
子类,但如果我将这些独特的子类用于我的页眉和页脚 View ,它就大有帮助了更容易解释上述 (lldb)
命令的结果。
@interface HeaderView : UIView
@end
@implementation HeaderView
@end
@interface FooterView : UIView
@end
@implementation FooterView
@end
关于iphone - 自动布局困惑 : Constraints for ScrollView with WebView and Header/Footer Views,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18489633/
我有一个程序可以打开一个窗口并快速改变背景颜色并随机弹出矩形和椭圆形。我的代码有效,但我不知道为什么,因为我没有在我的代码中调用 repaint() 函数。当我使用我个人的 update() 函数包含
var allRapidSpells = $$('input[value^=RSW]'); 谁能告诉我这是做什么的? 最佳答案 我敢猜测您正在使用 MooTools ,一个 JavaScript 框架
我有一个抽象父类,它有多个子类。我希望 child 能够拥有一个对于该 child 的每个实例都相同的变量。我不想将构造函数传递给 child 来告诉它它的名字,因为当它可以被硬编码时,这看起来很愚蠢
我刚刚在 Git 存储库上做了一些糟糕的事情,我不知道如何解决这个问题。我什至不知道我是怎么把它弄成这样的……! 在存储库(托管在 git hub 上)上,有 3 个我感兴趣的分支:master、br
我是 GIT 的新手,在理解提交日志图时遇到问题。 我感觉每条平行线都是一个分支。虽然我的源代码只有 2 个分支。我在下面提供的提交日志图中看到 3-4 条平行线(Microsoft Team Ser
我是 WPF 的新手,ScrollViewer 让我很沮丧。要么我只是没有“得到”它,要么它是一种有限的控制。 这是我的挫折: 水平滚动错误 水平滚动条仅在列表底部可见(我必须滚动到底部才能看到) 坏
那么 $('table.selectable td.capable input:text') 比 $('table.selectable td input:text') 更好吗?换句话说,指定一个类会
我刚刚完成了计算机图形学类(class),我们必须对光线追踪器进行编程。尽管所有结果都是正确的,但我对 OpenMP 的使用感到困惑(顺便说一句,这不是类(class)的一部分)。我有这个循环(C++
与 PatternSynonyms ( explicitly bidirectional form ),pattern-to-expr 方程实际上形成了一个函数,但拼写为大写(假设您最终得到正确类型的
我是 javascript/coffeescript 新手。 有人可以解释一下为什么这个 CoffeeScript/JavaScript 会毫无延迟地快速通过吗?我对第一种情况的想法是,它是对 upd
如果我调用document.getElementsByClassName('cl'),我会得到一个 HTMLCollection。它似乎包含 Element 对象而不是 HTMLElement 对象,
这是我本月的 azure payasyougo 使用费用。 我很难理解为什么我要为标准中型应用服务付费,我认为它会包含在计算时间中?我只运行一个云服务,这对于一个没有做太多事情的云服务来说似乎有点陡峭
除了the issue I am already having之外,我还在I saw a video on it之后安装了HBase(尚未安装)之前,还安装了Zookeeper。在安装它时,我遇到了许
我正在将 XSLT 与 regexp:match exslt 函数一起使用。上述函数采用 JavaScript Regex 模式。因此,我尝试匹配一组数字 1 到 3 OR 5 到 7 OR 9 到
我想知道为什么这段代码会给出消息:SyntaxError:意外的标记其他。 var compare = function(choice1,choice2){ if(choice1===choice2)
我尝试使用复选框和 JQuery 过滤日历上的事件, $(document).ready(function () { $('.scrollable-menu :checkbox').click(f
假设我们有一个用户想要一个名为:“test/lasdhjal.txt”,无论如何。现在,如果我将其放入新的文件(输入)中;对象里面,它会认为 test/是一个文件夹,而它是名称的一部分。我能做什么呢?
问题是 stash 的更改不会留在我 stash 它们的分支中。其他分支存储将被覆盖示例: 我愿意: git checkout iss4 // made some changes gi
我是一个 java 新手,并且在 StackOverflow 错误/在类之间访问文件的能力方面遇到了一个非常令人困惑的问题。我知道根本原因可能是我进行了一些递归调用,但修复它的语法却让我无法理解。我认
public X createData(int n) { int[] values = new int[n]; Random rand = new Random(); for
我是一名优秀的程序员,十分优秀!