{
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
/*
verticalScrollView.backgroundColor = [UIColor whiteColor];
verticalScrollView.pagingEnabled =NO;// 添加scrollView添加到父视图,并设置其约束
verticalScrollView.bounces = NO;
[self.view addSubview:verticalScrollView];
[verticalScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.and.right.mas_equalTo(0);
make.height.mas_equalTo(kScreenHeight);
}];
// 设置scrollView的子视图,即过渡视图contentSize,并设置其约束
UIView *verticalContainerView = [[UIView alloc]init];
[verticalScrollView addSubview:verticalContainerView];
[verticalContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.bottom.and.right.equalTo(verticalScrollView).with.insets(UIEdgeInsetsZero);
make.width.equalTo(verticalScrollView);
}];
*/
var scroll: UIScrollView = UIScrollView()
self.view.addSubview(scroll)
scroll.snp.makeConstraints { (m) in
m.leading.equalToSuperview()
m.bottom.trailing.equalToSuperview()
m.height.equalToSuperview()
}
var content: UIView = UIView()
scroll .addSubview(content)
content.snp.makeConstraints { (m) in
m.top.leading.bottom.trailing.equalToSuperview().inset(0)
m.width.equalToSuperview()
}
/*
UIView *lastView;
UIImageView *imageview = ({
UIImageView *imageview = [UIImageView new];
imageview.image = [UIImage imageNamed:@"shezhi_gy_1"];
imageview;
});
[verticalContainerView addSubview:imageview];
[imageview mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.left.right.equalTo(verticalContainerView);
make.height.equalTo(@(212*kScreenWidth/375.0));
}];
lastView = imageview;
*/
var last: UIView?
var aview: UIView = UIView()
aview.backgroundColor = .red
content.addSubview(aview)
aview.snp.makeConstraints { (m) in
m.top.equalToSuperview()
m.leading.trailing.equalToSuperview()
m.height.equalTo(10)
}
last = aview
if true {
for i in 1...10 {
var aview: UIView = UIView()
aview.backgroundColor = randomColor()
content.addSubview(aview)
aview.snp.makeConstraints { (m) in
m.top.equalTo(last!.snp.bottom).offset(10)
m.leading.trailing.equalToSuperview()
m.height.equalTo(100)
}
last = aview
}
}
//
//
// [verticalContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
//
// make.bottom.equalTo(lastView.mas_bottom);
// }];
content.snp.makeConstraints { (m) in
m.bottom.equalTo(last!)
}
}
}
网友评论