实现collectionview加载到tableview的tableFooterView上一起滑动(类似淘宝购物车)--通过添加观察者实现
来源:互联网 发布:中学生学编程学什么好 编辑:程序博客网 时间:2024/06/05 07:39
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title = @"交易成功"; self.view.backgroundColor = [UIColor whiteColor]; self.navigationItem.leftBarButtonItem = [BackButtonItem getBackItemWithTitle:@"" image:[UIImage imageNamed:@"fl_fanhui-jian"] target:self action:@selector(goBackPage:)]; //右侧确认按钮 self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom]; self.rightBtn.userInteractionEnabled = YES; [self.rightBtn setImage:[UIImage imageNamed:@"gengduoanniu"] forState:UIControlStateNormal]; self.rightBtn.titleLabel.font = MIDDLE_LIT_FONT; [self.rightBtn setTitleColor:THEME_GREEN_COLOR forState:UIControlStateNormal]; [self.rightBtn addTarget:self action:@selector(clickedRightBtn:) forControlEvents:UIControlEventTouchUpInside]; self.rightBtn.frame = CGRectMake(0, 0, 40, 30) ; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:self.rightBtn]; [self drawMainViewPage];}-(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.navigationController.navigationBar.translucent = YES; [self.myColView reloadData];}-(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated];}-(void)drawMainViewPage{ self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH) style:UITableViewStylePlain]; [self.view addSubview:self.myTableView]; [self.myTableView mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.view.mas_top); make.left.right.bottom.mas_equalTo(self.view); }]; self.myTableView.backgroundColor = BKG_HEX_GRAY_EEE; [self.myTableView layoutIfNeeded]; self.myTableView.delegate = self; self.myTableView.dataSource = self; self.myTableView.estimatedRowHeight = 49; self.myTableView.rowHeight = UITableViewAutomaticDimension; [self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone; // [self drawHeaderView]; [self drawFooterCol];}-(void)drawHeaderView{ self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,190)]; self.myTableView.tableHeaderView = self.headerView; self.headerView.backgroundColor = [UIColor whiteColor]; //上 self.headerImgv = [[UIImageView alloc]init]; self.headerImgv.backgroundColor = [UIColor whiteColor]; self.headerImgv.image = [UIImage imageNamed:@"jiaoyiwanchengtupian"]; [self.headerView addSubview:self.headerImgv]; [self.headerImgv mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.headerView.mas_top); make.left.right.mas_equalTo(self.headerView); make.height.mas_equalTo(SCREEN_WIDTH*(124/375.0)); }]; [self.headerImgv layoutIfNeeded]; CGFloat widht_btn = (SCREEN_WIDTH-40*2- 18)/2.0; self.liJiPJBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [self.headerView addSubview:self.liJiPJBtn]; self.liJiPJBtn.layer.borderColor = TEXT_HEX_MID_GRAY.CGColor; self.liJiPJBtn.layer.borderWidth = 1; self.liJiPJBtn.layer.cornerRadius = 20/2.0; self.liJiPJBtn.titleLabel.font = BIG_B_FONT; [self.liJiPJBtn setTitle:@"立即评价" forState:UIControlStateNormal]; [self.liJiPJBtn setTitleColor:TEXT_HEX_LIGHT_L_GRAY forState:UIControlStateNormal]; [self.liJiPJBtn addTarget:self action:@selector(clickedLiJIPIngJiaBtn:) forControlEvents:UIControlEventTouchUpInside]; [self.liJiPJBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.headerView.mas_left).mas_offset(40); make.top.mas_equalTo(self.headerImgv.mas_bottom).mas_offset(22); make.size.mas_equalTo(CGSizeMake(widht_btn, 40)); }]; self.dingDxqBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [self.headerView addSubview:self.dingDxqBtn]; self.dingDxqBtn.layer.borderColor = TEXT_HEX_MID_GRAY.CGColor; self.dingDxqBtn.layer.borderWidth = 1; self.dingDxqBtn.layer.cornerRadius = 20/2.0; self.dingDxqBtn.titleLabel.font = BIG_B_FONT; [self.dingDxqBtn setTitle:@"订单详情" forState:UIControlStateNormal]; [self.dingDxqBtn setTitleColor:TEXT_HEX_LIGHT_L_GRAY forState:UIControlStateNormal]; [self.dingDxqBtn addTarget:self action:@selector(clickedDingDanXiangQingaBtn:) forControlEvents:UIControlEventTouchUpInside]; [self.dingDxqBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.liJiPJBtn.mas_right).mas_offset(18); make.top.mas_equalTo(self.headerImgv.mas_bottom).mas_offset(22); make.size.mas_equalTo(CGSizeMake(widht_btn, 40)); }]; self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH,self.headerImgv.frame.size.height+22+40+22);}-(void)drawFooterCol{ self.footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 90)]; self.myTableView.tableFooterView = self.footView; self.footView.backgroundColor = [UIColor clearColor]; [self drawTitleCollection]; [self drawColPage];}-(void)drawColPage{ //284/376 CGFloat cellWidth = (SCREEN_WIDTH-20-10)/2.0; CGFloat cellHeight = cellWidth*(188/167.0); self.flowLayout = [[UICollectionViewFlowLayout alloc]init]; self.flowLayout.itemSize = CGSizeMake(cellWidth, cellHeight+10); self.flowLayout.minimumLineSpacing = 10; self.flowLayout.minimumInteritemSpacing = 10; self.flowLayout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10); self.flowLayout.footerReferenceSize = CGSizeMake(self.myTableView.bounds.size.width, 0.0001); self.flowLayout.headerReferenceSize = CGSizeMake(self.myTableView.bounds.size.width, 0.0001); self.myColView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH) collectionViewLayout:self.flowLayout]; self.myColView.delegate = self; self.myColView.dataSource = self; self.myColView.bounces = YES; self.myColView.scrollEnabled = NO; self.myColView.backgroundColor = [UIColor whiteColor]; self.myColView.showsHorizontalScrollIndicator = NO; self.myColView.showsVerticalScrollIndicator = NO; [self.footView addSubview:self.myColView]; [self.myColView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.labelTL.mas_bottom).mas_offset(TEXT_EDGE_DISTANCE); make.left.right.mas_equalTo(self.footView); make.height.mas_equalTo(100); }]; [self.myColView registerClass:[SearchGoodsColCell class] forCellWithReuseIdentifier:@"SearchGoodsColCell_order"]; [self.myColView layoutIfNeeded]; [self.myColView addObserver:self forKeyPath:@"contentSize" options:0 context:NULL]; }//监听contentSize变化改变约束- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { CGRect frame = self.myColView.frame; frame.size = self.myColView.contentSize; self.footView.frame = CGRectMake(0, 0, SCREEN_WIDTH, frame.size.height); [self.footView layoutIfNeeded]; self.myTableView.tableFooterView = self.footView; [self.myColView mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.labelTL.mas_bottom).mas_offset(TEXT_EDGE_DISTANCE); make.left.right.mas_equalTo(self.footView); make.height.mas_equalTo(frame.size.height); }];}-(void)drawTitleCollection{ //你喜欢 self.labelTL = [[UILabel alloc]init]; [self.footView addSubview:self.labelTL]; self.labelTL.font = MIDDLE_LIT_FONT; self.labelTL.textColor = RGB(141, 139, 140); self.labelTL.text = @"猜你喜欢"; [self.labelTL mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.footView.mas_centerX); make.top.mas_equalTo(self.footView.mas_top).mas_offset(TEXT_EDGE_DISTANCE); }]; [self.labelTL layoutIfNeeded]; //左线 UIView *leftVLine = [[UIView alloc]init]; [self.footView addSubview:leftVLine]; leftVLine.backgroundColor = RGB(141, 139, 140); [leftVLine mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.labelTL.mas_centerY); make.right.mas_equalTo(self.labelTL.mas_left).mas_offset(-TEXT_EDGE_DISTANCE); make.size.mas_equalTo(CGSizeMake(33, 0.5)); }]; //右线 UIView *rightVLine = [[UIView alloc]init]; [self.footView addSubview:rightVLine]; rightVLine.backgroundColor = RGB(141, 139, 140); [rightVLine mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.labelTL.mas_centerY); make.left.mas_equalTo(self.labelTL.mas_right).mas_offset(TEXT_EDGE_DISTANCE); make.size.mas_equalTo(CGSizeMake(33, 0.5)); }];}#pragma mark -- collectionVeiw delegate ---(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1;}-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return 10;}-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ SearchGoodsColCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SearchGoodsColCell_order" forIndexPath:indexPath]; return cell;}-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"选择商品 %ld",indexPath.row); }#pragma mark -- tableview delegate ---(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1;}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 0;}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell;}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //可以注释 [tableView deselectRowAtIndexPath:indexPath animated:NO]; }-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 0.0001;}-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.0001;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}#pragma mark -- clickedDingDanXiangQingaBtn 订单详情 ---(void)clickedDingDanXiangQingaBtn:(UIButton *)sender{ NSLog(@"clickedDingDanXiangQingaBtn 订单详情"); MineOrderDetailViewController *vc = [[MineOrderDetailViewController alloc]init]; [self.navigationController pushViewController:vc animated:YES];}#pragma mark -- clickedLiJIPIngJiaBtn ---(void)clickedLiJIPIngJiaBtn:(UIButton *)sender{ NSLog(@"clickedLiJIPIngJiaBtn 评价"); MinePublishPingLunViewController *vc = [[MinePublishPingLunViewController alloc]init]; [self.navigationController pushViewController:vc animated:YES];}#pragma mark -- clickedRightBtn 右键 ---(void)clickedRightBtn:(UIButton *)sender{ NSLog(@"clickedRightBtn 右键"); NSMutableArray *arr_tit = [@[@"首页 ",@"帮助 ",@"我要吐槽"] mutableCopy]; NSMutableArray *arr_tu = [@[@"shouye-biao",@"bangzhu-biao",@"woyaotucao-biao"] mutableCopy]; [YBPopupMenu showRelyOnView:sender titles:arr_tit icons:arr_tu menuWidth:120 otherSettings:^(YBPopupMenu *popupMenu) { popupMenu.delegate = self; popupMenu.fontSize = 12; popupMenu.textColor = TEXT_HEX_LIGHT_L_GRAY; }];}#pragma mark - YBPopupMenuDelegate- (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu{ NSLog(@"点击了 %ld 选项",index);}#pragma mark -- goBackPage 返回 ---(void)goBackPage:(id)sender{ [self.navigationController popViewControllerAnimated:YES];}
阅读全文
0 0
- 实现collectionview加载到tableview的tableFooterView上一起滑动(类似淘宝购物车)--通过添加观察者实现
- iOS开发——仿淘宝添加到购物车的动画效果实现
- iOS开发仿淘宝添加到购物车的动画效果实现
- tableview上cell 加载collectionview
- android实现类似淘宝的底部滑动导航菜单
- 类似淘宝添加购物动画
- 观察者模式实现上下一起滑动
- 仿淘宝购物车的实现
- 淘宝购物车功能的实现
- 实现京东底部添加到购物车的效果
- Android实现淘宝购物车
- 实现淘宝购物车功能
- JQuery和JS怎样实现淘宝购物车的添加和删除?
- 用JS实现类似淘宝购物图片切换
- 使用RecycleView加载不同的布局(类似淘宝京东购物车+推荐商品列表)
- 实现tableView和collectionView的相互关联方法
- Android开发-实现pulltorefresh上类似购物车加减方法和EditText焦点问题的解决方法
- RadioButton组也可通过添加上HorizontalScrollView 实现左右滑动
- matplotlib 画图
- 【转载】从单体架构迁移到微服务,8个关键的思考、实践和经验
- Java POI导出Excel
- LeetCode 之 String to Integer (atoi)
- ./configure,make,make install的作用
- 实现collectionview加载到tableview的tableFooterView上一起滑动(类似淘宝购物车)--通过添加观察者实现
- 前台一些问题样式,显示问题
- TensorFlow使用的一个小案例
- 【精】客户端(iOS、Android)/Server,APP内部的通信协议,跨平台方案
- Mybatis系列---强大的动态SQL
- 导航栏二级悬浮菜单样式
- 数据库范式
- AmazonS3文档——对象存储的用法之《存储桶操作》
- Classroom Watch (Codeforces Round #441 (Div.2) )