#import "ViewController.h"@interface ViewController ()@property (nonatomic,strong) UIScrollView *scroView;
@property (nonatomic,strong)UIImageView *image;
@property (nonatomic,strong)UIScrollView *itemScro;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UITableView *tableView2;
@property (nonatomic,strong) UIView *midView;
@property (nonatomic,strong)UIButton *leftBtn;
@property (nonatomic,strong)UIButton *rightBtn;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.view addSubview:self.scroView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.tag == 111) {
if (scrollView.contentOffset.y>=375-64) {
if (self.itemScro.contentOffset.x == 375) {
self.tableView2.scrollEnabled = YES;
self.scroView.scrollEnabled = NO;
}else{
self.tableView.scrollEnabled = YES;
self.scroView.scrollEnabled = NO;
}
}
}
if (scrollView.tag == 333) {
if (self.tableView2.contentOffset.y<0) {
self.tableView2.scrollEnabled = NO;
self.scroView.scrollEnabled = YES;
}
}
if (scrollView.tag == 222) {
if (self.tableView.contentOffset.y<0) {
self.tableView.scrollEnabled = NO;
self.scroView.scrollEnabled = YES;
}
}
}
-(UIScrollView *)scroView{
if (!_scroView) {
_scroView =[[UIScrollView alloc]initWithFrame:self.view.bounds];
_scroView.contentSize = CGSizeMake(375, 667+375-64);
_scroView.tag = 111;
_scroView.delegate = self;
UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375, 375)];
topView.backgroundColor = [UIColor redColor];
[_scroView addSubview:topView];
self.midView = [[UIView alloc]initWithFrame:CGRectMake(0, 375, 375, 40)];
self.midView.backgroundColor = [UIColor orangeColor];
self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[self.leftBtn setTitle:@"左边" forState:UIControlStateNormal];
// [leftBtn setTitle:<#(nullable NSString *)#> forState:<#(UIControlState)#>]
self.leftBtn.frame = CGRectMake(0, 0, self.view.bounds.size.width*0.5, 40);
[self.leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[self.rightBtn setTitle:@"右边" forState:UIControlStateNormal];
self.rightBtn.frame = CGRectMake(self.view.bounds.size.width*0.5, 0, self.view.bounds.size.width*0.5, 40);
[self.rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self.midView addSubview:self.leftBtn];
[self.midView addSubview: self.rightBtn];
[_scroView addSubview:self.midView];
self.itemScro = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 375+40, 375, 667-40)];
self.itemScro.pagingEnabled = YES;
self.itemScro.scrollEnabled = NO;
self.itemScro.contentSize = CGSizeMake(375*2, 667-40);
self.itemScro.backgroundColor = [UIColor purpleColor];
self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 375, 667-40) style:(UITableViewStylePlain)];
self.tableView.scrollEnabled = NO;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.tag = 222;
self.tableView.backgroundColor = [UIColor redColor];
[ self.itemScro addSubview:self.tableView];
self.tableView2 = [[UITableView alloc]initWithFrame:CGRectMake(375, 0, 375, 667-40) style:(UITableViewStylePlain)];
self.tableView2.scrollEnabled = NO;
self.tableView2.delegate = self;
self.tableView2.dataSource = self;
self.tableView2.tag = 333;
[ self.itemScro addSubview:self.tableView2];
[_scroView addSubview: self.itemScro];
}
return _scroView;
}
-(void)rightBtnClick{
[self.itemScro setContentOffset:CGPointMake(375, 0)];
self.midView.frame = CGRectMake(0, 0, 375, 104);
}
-(void)leftBtnClick{
[self.itemScro setContentOffset:CGPointMake(0, 0)];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 100;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"test"];
if (cell==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"test"];
}
cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
return cell;
}
@end
网友评论