1、SingleViewApplication项目,先拖动一个ScrollView控件设置整个屏幕,然后再放一个View控件到ScrollView上,同样也是全屏幕,然后添加几个按钮上去,竖着摆放。然后add missing constrain自动添加约束,给ScrollView和View添加输出口。
2、代码如下:
//
// ViewController.m
// TestProject
//
// Created by 侯家奇 on 16/8/17.
// Copyright © 2016年 侯家奇. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIView *contentView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.contentView.frame = CGRectMake(0, 0, self.view.frame.size.width, 2000);
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 2000);
}
@end