@interface ViewController ()<UIScrollViewDelegate>
@property (nonatomic, strong) TestScrollView *scr1;
@property (nonatomic, strong) UIScrollView *scr2;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.scr1];
}
- (UIScrollView *)scr1 {
if (!_scr1) {
_scr1 = [[UIScrollView alloc] init];
CGFloat width = [UIScreen mainScreen].bounds.size.width;
CGFloat height = [UIScreen mainScreen].bounds.size.height;
_scr1.frame = CGRectMake(0, 0, width, height);
_scr1.backgroundColor = [UIColor orangeColor];
_scr1.contentSize = CGSizeMake(width * 2, height);
_scr1.pagingEnabled = YES;
_scr1.delegate = self;
[_scr1 addSubview:self.scr2];
}
return _scr1;
}
- (UIScrollView *)scr2 {
if (!_scr2) {
_scr2 = [[UIScrollView alloc] init];
CGFloat width = [UIScreen mainScreen].bounds.size.width;
CGFloat height = [UIScreen mainScreen].bounds.size.height;
_scr2.frame = CGRectMake(0, 50, width, height - 50);
_scr2.backgroundColor = [UIColor blueColor];
_scr2.contentSize = CGSizeMake(width * 2, 0);
_scr2.pagingEnabled = YES;
_scr2.delegate = self;
}
return _scr2;
}
@end
近期评论