【发布时间】:2013-08-22 21:22:48
【问题描述】:
目标:
使用自动布局约束,让UIWebView 的宽度与其父视图相同,即UIScrollView。
代码
NSLayoutConstraint *makeWidthTheSameAsScrollView =[NSLayoutConstraint
constraintWithItem:self.questionWebView
attribute:NSLayoutAttributeWidth
relatedBy:0
toItem:self.masterScrollView
attribute:NSLayoutAttributeWidth
multiplier:1.0
constant:0];
[self.view addConstraint:makeWidthTheSameAsScrollView];
NSLog(@"The width of questionWebView *AFTER* adding the constrain is: %f", self.questionWebView.frame.size.width);
NSLog(@"The width of scrollView *AFTER* adding the constrain is: %f", self.masterScrollView.frame.size.width);
当前结果
当我记录self.questionWebView(UIWebView)的宽度时,应用自动布局约束时它的宽度不会改变。
问题
- 这是正确的方法吗?
- 我做错了什么?
p.s 我知道在 UIScrollView 中放置 UIWebView 是违反 Apple 的建议的,但是我已经关闭了使用属性 self.questionWebView.userInteractionEnabled = NO; 滚动 UIWebView 的功能。目前使用 UIWebView 是我显示 HTML 表格的最佳策略。
【问题讨论】:
标签: ios uiwebview uiscrollview autolayout