頂部菜單欄切換,懸浮

#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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容