惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
A
Arctic Wolf
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
S
Schneier on Security
The Cloudflare Blog
Security Latest
Security Latest
S
SegmentFault 最新的问题
L
Lohrmann on Cybersecurity
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cyber Attacks, Cyber Crime and Cyber Security
K
Kaspersky official blog
Latest news
Latest news
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏
P
Privacy & Cybersecurity Law Blog
F
Fortinet All Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
美团技术团队
博客园 - 叶小钗
H
Help Net Security
博客园 - 【当耐特】
云风的 BLOG
云风的 BLOG
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
A
About on SuperTechFans
WordPress大学
WordPress大学
Cloudbric
Cloudbric
IT之家
IT之家
Last Week in AI
Last Week in AI
S
Securelist
Google Online Security Blog
Google Online Security Blog
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
L
LINUX DO - 最新话题
Know Your Adversary
Know Your Adversary
爱范儿
爱范儿
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
Google Developers Blog
C
CERT Recently Published Vulnerability Notes
宝玉的分享
宝玉的分享
博客园 - Franky
TaoSecurity Blog
TaoSecurity Blog
P
Proofpoint News Feed
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
L
LINUX DO - 热门话题
N
News and Events Feed by Topic
B
Blog

Dvel's Blog

Rime 全拼双拼混输 CHD 油猴脚本:每日签到自动答题 Rime 配置:雾凇拼音 Hammerspoon 自动切换输入法 修复 Hugo 本地图片的累计布局偏移(CLS)问题 macOS 利用 Karabiner 修改 Emacs 键位为 Vim 键位 macOS 修改 Emacs 键位为 Vim 键位 Surge 配置 汉字的混乱 Netflix 中英双语字幕的好办法 优化 Rime 英文输入体验 判断字符是否为简体字或繁体字 Cloudflare 转入域名提示「出现了问题。请重试转移此域。尚未向您收费。」 图片压缩:Squoosh、TinyPNG、ImageOptim、WebP macOS grep + sed 批量替换多个文件的内容 在 macOS 根目录创建文件夹 博客图床小妙招 折腾 Hugo & PaperMod 主题 利用 Cloudflare Workers 进行批量 301 重定向 将博客部署在 Cloudflare Pages Alfred File Navigation(文件导航器)详解 在 Hugo Goldmark Markdown 中设置以新标签打开链接 日期与时间(UTC、GMT、时间戳、时区) 让 Alfred 以新标签的方式打开 Finder 用 git filter-branch 给 Git 仓库瘦身 qBittorrent 设置教程 联通光猫破解+桥接记录 配置 Mac 终端走代理 Steam for Mac 中文游戏推荐 我的 Mac 软件/工具列表 《Flask Web 开发》笔记 用 sleepwatcher 让 Mac 在睡眠及唤醒时自动执行一些脚本 解决 pyenv 导致的 brew warning 《SQL 必知必会》笔记 Git 自总结 Python 异步 IO 笔记 再见,双点医院! 用 CloudXNS 解决 CNAME 与 MX 记录冲突 你好,Hugo! 为 Mac 打造 zsh command line 环境 新 Mac 新装修 秦皇岛暑期自驾的烦恼 苹果公司开发者账号申请流程 解决 CocoaPods 的类库 import 没有提示 iOS 使用 CocoaPods 的快速回顾 GitBook 简单生成本地静态 HTML 的方法 你好, Hexo! About
UIScrollView 中使用 Masonry
Dvel · 2017-04-25 · via Dvel's Blog

昨天耽误了一阵子在 scrollView 的布局上,记录一下。

如果可以提前确定 scrollViewcontentSize,就简单多了,但这种情况很少。

一般还是按照 subViews 自适应的比较合适,这样就需要一个 containerView 来撑起 scrollViewcontentSize

简单的代码示例:

UIScrollView *scrollView = [UIScrollVie new];
[self.view addSubview:scrollView];
                            
UIView *containerView = [UIView new];
[scrollView addSubview:containerView];
                            
UIView *v1 = [UIView new];
v1.backgroundColor = [UIColor redColor];
[containerView addSubview:v1];
                            
UIView *v2 = [UIView new];
v2.backgroundColor = [UIColor blueColor];
[containerView addSubview:v2];
                
/*
如上,我想让v1、v2纵向排列,让scrollView可以上下滚动。
*/

// scrollView正常进行约束
[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(self.view);
}];
                      
// 容器视图
[containerView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.width.equalTo(scrollView); // 试了发现这里好像必须要约束一下width
}];
                      
// v1、v2都放在容器里
[v1 mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.left.right.equalTo(containerView);
    make.height.equalTo(@400);
}];
[v2 mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(v1.mas_bottom);
    make.left.right.equalTo(v1);
    make.height.equalTo(@400);
}];

// 这里需要补刀,来撑起contentSize
[containerView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.bottom.equalTo(v2);
}];