小气泡功能在中的两种实现方案

本文涉及的产品
可视分析地图(DataV-Atlas),3 个项目,100M 存储空间
简介: 小气泡功能在中的两种实现方案

看到别人的app有小气泡感觉很好玩,并且他们的宽高都不超过所在单元格的宽高,其实它也没有什么神奇我们可以用两种方案来实现:控件方案和多视图方案。

第一种方案:控件法。已经实现一个页面有一个气泡的情况。可以抽象出一个类,调用它就可以了,理论上也可以实现多气泡的情况。可以通过申请一个小气泡对象,制定小黑条的宽度,预置显示的内容。通过self.buttonH5.buttonPressed = ^(NSInteger tag)来实现点击小黑框内容的页面跳转。

实际页面:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    if (indexPath.section == 1) {
    .
    .
    .
             if (![[self.dictData valueForKey:@"consigneeTel"]  isEqualToString:@""])
//        if (2 == [[self.dictData valueForKey:@"quickType"] longValue])
        {
            //普通发单

//            if (1 == [[self.dictData valueForKey:@"quickType"] longValue])
            {
                UIButton* buttonDetail =[UIButton buttonWithType:UIButtonTypeCustom];
                buttonDetail.frame = CGRectMake(0, 0, 40 , 40);
                UIImage *image1 = [UIImage imageNamed:@"prompt_fare_card"];
                [buttonDetail setImage:image1 forState:UIControlStateNormal];
                [buttonDetail.imageView sizeToFit];
                [buttonDetail addTarget:self action:@selector(buttonDetail) forControlEvents:UIControlEventTouchUpInside];
                [buttonDetail setCenter:CGPointMake(WINDOW_WIDTH-18, labelSuceessed.center.y)];
                [contentCell addSubview:buttonDetail];


                long lEstimated = [[self.dictData valueForKey:@"estimated"] longValue];
                if(1 == lEstimated)
                {
                    self.buttonH5 = [[ButtonDetailH5 alloc]initWithFrame:CGRectMake(0, 0, 257, 44)];
                    self.buttonH5.center = CGPointMake(WINDOW_WIDTH-15-self.buttonH5.bounds.size.width/2, buttonDetail.center.y-25);
//                    float lDistance = [[self.dictData valueForKey:@"walkingDistance"] longValue];
//                    lDistance = lDistance/1000;
                    _fFreight = [[self.dictData valueForKey:@"freight"] longValue];
                    _fFreight = _fFreight/100;
                    if(_distance >= 1000)
                    {
                        dDistance = dDistance/1000;
                        self.buttonH5.labelBut.text = [NSString stringWithFormat:@"实际配送%.2f公里,应付运费%.2f元", dDistance, _fFreight];
                    }
                    else if(_distance >= 0)
                    {
                        self.buttonH5.labelBut.text = [NSString stringWithFormat:@"实际配送%ld米,应付运费%.2f元", (long)dDistance, _fFreight];
                    }
                    else
                    {
                        self.buttonH5.labelBut.text = [NSString stringWithFormat:@"实际配送--公里,应付运费%.2f元", _fFreight];
                    }
//                    self.buttonH5.labelBut.text = [NSString stringWithFormat:@"实际配送%.2f公里,应付运费%.2f元", lDistance, fFreight];
                }
                else
                {
                    self.buttonH5 = [[ButtonDetailH5 alloc]initWithFrame:CGRectMake(0, 0, 230, 44)];
                    self.buttonH5.center = CGPointMake(WINDOW_WIDTH-15-self.buttonH5.bounds.size.width/2, buttonDetail.center.y-25);
                    self.buttonH5.labelBut.text = @"具体运费最终由实际配送里程决定";

                }
                self.buttonH5.hidden = YES;
                __weak __typeof(self)safeSelf = self;
                self.buttonH5.buttonPressed = ^(NSInteger tag){
                    //加载H5的位置
                    FeeWebViewController *feeWebViewController = [[FeeWebViewController alloc] init];
                    if(safeSelf.strWayBillld.length > 0)
                    {
                        feeWebViewController.waybillId = safeSelf.strWayBillld;
                        feeWebViewController.title = @"配送运费";
                        [safeSelf.navigationController pushViewController:feeWebViewController animated:YES];
                        safeSelf.buttonH5.hidden = YES;
                    }
                };
                [contentCell addSubview:self.buttonH5];

            }
       }
       .
       .
       .
    }
}       
-(void)buttonDetail{

    if (self.buttonH5.hidden==NO) {
          self.buttonH5.hidden = YES;
    }else{
         self.buttonH5.hidden = NO;
    }

}

下面是抽象出来的小气泡类。

ButtonDetailH5.h

#import <UIKit/UIKit.h>
@interface ButtonDetailH5 : UIButton
@property (strong, nonatomic) UIImageView *imageViewbut;
@property (strong, nonatomic) UIImageView *imageViewbutIcon;
@property (strong, nonatomic) UILabel *labelBut;
@property (strong, nonatomic) UIButton* buttonBut;
@property (copy, nonatomic) void(^buttonPressed)(NSInteger tag);
-(instancetype)initWithFrame:(CGRect)frame;
@end

ButtonDetailH5.m


#import "ButtonDetailH5.h"

@implementation ButtonDetailH5
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.imageViewbut = [[UIImageView alloc]initWithFrame:CGRectMake(12, -2, frame.size.width, frame.size.height-5)];
        UIImage *image = [UIImage imageNamed:@"prompt_fare_box_card"];
        //UIEdgeInsets insets = UIEdgeInsetsMake(5.0f, 5.0f, 5.0f, 5.0f);
        NSInteger leftCapWidth = image.size.width * 0.5f;
        // 顶端盖高度
        NSInteger topCapHeight = image.size.height * 0.5f;
        // 重新赋值
        image = [image stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];
        self.imageViewbut.image = image;
        [self addSubview:self.imageViewbut];




        self.imageViewbutIcon = [[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width-7, frame.size.height-5 - 2, 8, 4)];

        self.imageViewbutIcon.image = [UIImage imageNamed:@"prompt_fare_arrow_card.png"];
        [self addSubview:self.imageViewbutIcon];




        self.labelBut = [[UILabel alloc]initWithFrame:self.imageViewbut.frame];
        self.labelBut.text = @"  实际配送125.565公里,应付运费134.34元";
        self.labelBut.font = [UIFont systemFontOfSize:12];
        self.labelBut.center = CGPointMake(self.labelBut.center.x+10, self.labelBut.center.y);
        self.labelBut.textColor = [UIColor whiteColor];
        self.labelBut.textAlignment = NSTextAlignmentLeft;
        [self addSubview:self.labelBut];

        self.buttonBut = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.buttonBut setTitle:@"详情" forState:UIControlStateNormal];
        self.buttonBut.frame = CGRectMake(frame.size.width-40 + 15, -4, 44, 44);
        self.buttonBut.titleLabel.font = [UIFont systemFontOfSize:12];
        [self.buttonBut setTitleColor:[UIColor colorWithHex:0x007aff] forState:UIControlStateNormal];
        [self.buttonBut addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
        self.buttonBut.tag = 2;

        [self addSubview:self.buttonBut];
        self.tag = 1;
        [self addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];



    }
    return self;
}
-(void)button:(UIButton* )sender{
    if (self.buttonPressed) {
        self.buttonPressed(sender.tag);
    }
}


@end

第二种方案:多视图方案,对不同单元格斗加入2个uiview(一个显示长内容信息,另一个显示短内容信息),通过数据源控制uiview的显示和隐藏。又称多气泡法,有无气泡不确定。具体是一张表有很多记录,每个单元格都有可能有小气泡,也可能没有(本质是有只是把它隐藏了),点击小气泡会显示小黑条,每个小黑条显示的内容不长度不同,点击小黑条进入不同的h5页面,点击其它非气泡按钮,滚动表格,选择表格的行事件小黑条隐藏,点击气泡若以前有小黑条显示就隐藏小黑条并显示本气泡的小黑条,若没有只显示本气泡的小黑条。这种气泡我采用的是对每个cell建立一个带xib对象,增加相关控件。有气泡按钮过小增加透明按钮的处理,分解小黑条的按钮图片文字3个button。在表格加载函数中处理小气泡和小黑条的显示和指针记录。点击气泡时我记录了当前数据的行数,和显示UIVIEW。我定义两个UIVIEW为显示不同长度的小黑条。

实际页面:多个小气泡。


实际页面:多个小气泡之间的互斥,只能显示一个小黑条,并且滑动表格,小黑条消失,点击小黑条跳到html5页面。



实际页面:多个小气泡之间的互斥,只能显示一个小黑条,并且滑动表格,小黑条消失,点击小黑条由于没有计费策略所以跳到html5页面又跳回来。


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if((self.arratData.count <= indexPath.section) || (0== self.arratData.count))
    {
        return nil;
    }
    UITableViewCell* cell = nil;
        UITableViewCell* cell = nil;
//    NSString *consigneeAddressStr = nil;
    long lEstimated =  0;
    double lDistance = 1001.0;
    long lQuickType = 2;
    float fFreight = 0.0;
//    NSString * fFreightStr = nil;
    double consigneeLogitude = 0.0;
    double consigneeLatitude = 0.0;
    if ([self.strType isEqualToString:@"lanshou"]) {
            static NSString *cellIdentifier = @"OrderWaitLanLanTableViewCell";
            OrderWaitLanLanTableViewCell *cellLanShou =(OrderWaitLanLanTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

            if (!cellLanShou) {
                UINib* nib =[UINib nibWithNibName:@"OrderWaitLanLanTableViewCell" bundle:nil];
                [tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
                cellLanShou = (OrderWaitLanLanTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
            }
            lQuickType = [[[self.arratData  objectAtIndex:indexPath.section]valueForKey:@"quickType"] longValue];
            lEstimated = [[[self.arratData  objectAtIndex:indexPath.section]valueForKey:@"estimated"] longValue];
            consigneeLogitude = [[[self.arratData  objectAtIndex:indexPath.section]valueForKey:@"consigneeLongitude"] doubleValue];
            consigneeLatitude = [[[self.arratData  objectAtIndex:indexPath.section]valueForKey:@"consigneeLatitude"] doubleValue];
            if((0 == consigneeLogitude) || (0 == consigneeLatitude))
            {
                cellLanShou.labelPeiSongFei.text =[NSString stringWithFormat:@"运   费:  %.2f元 (预估)", [[[self.arratData  objectAtIndex:indexPath.section]valueForKey:@"freight"] floatValue]/100];
            }
            else
            {
                cellLanShou.labelPeiSongFei.text = [NSString stringWithFormat:@"运   费:  %.2f元", [[[self.arratData  objectAtIndex:indexPath.section]valueForKey:@"freight"] floatValue]/100];
            }
            UIImage *image = [UIImage imageNamed:@"prompt_fare_box_card"];
            NSInteger leftCapWidth = image.size.width * 0.5f;
            // 顶端盖高度
            NSInteger topCapHeight = image.size.height * 0.5f;
            // 重新赋值
            image = [image stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];

            if((1 == lQuickType) && (1 == lEstimated) && (consigneeLatitude > 0) && (consigneeLogitude > 0))
            {
                fFreight = [[[self.arratData  objectAtIndex:indexPath.section]valueForKey:@"freight"] longValue];
                fFreight = fFreight/100;
                lDistance = [[[self.arratData  objectAtIndex:indexPath.section]valueForKey:@"walkingDistance"] integerValue];
                if(lDistance >= 0)
                {
                    fFreight = [[[self.arratData  objectAtIndex:indexPath.section]valueForKey:@"freight"] longValue];
                    fFreight = fFreight/100;
                    if(lDistance >= 1000)
                    {
                        lDistance = lDistance/1000;
                        [cellLanShou.contentDisplayBtn setTitle:[NSString stringWithFormat:@"  实际配送%.2f公里,应付运费%.2f元", lDistance, fFreight] forState:UIControlStateNormal];
                    }
                    else
                    {
                        [cellLanShou.contentDisplayBtn setTitle:[NSString stringWithFormat:@"  实际配送%ld米,应付运费%.2f元", (long)lDistance, fFreight] forState:UIControlStateNormal];
                    }
                }
                else
                {
                    [cellLanShou.contentDisplayBtn setTitle:[NSString stringWithFormat:@"  实际配送--公里,应付运费%.2f元", fFreight] forState:UIControlStateNormal];
                }
//                [[self.arratData  objectAtIndex:indexPath.section] setValue:@"" forKey:@"walkingRouteDistance"];
                [cellLanShou.contentDisplayBtn setBackgroundImage:image forState:UIControlStateNormal];
                cellLanShou.contentBtn.row = indexPath.section;
                cellLanShou.contentBtn.contentUIView = cellLanShou.contentDetailView;
                cellLanShou.contentBtn.contentDisplayButton = cellLanShou.contentDisplayBtn;
                [cellLanShou.contentBtn addTarget:self action:@selector(buttonPressedContent:) forControlEvents:UIControlEventTouchUpInside];
                cellLanShou.detailBackgroundBtn.contentUIView = cellLanShou.contentDetailView;
                cellLanShou.detailBackgroundBtn.isShortBtn = NO;
            }
            else
            {
                cellLanShou.contentShortBtn.contentDisplayButton = nil;
                [cellLanShou.contentDisplayShortBtn setBackgroundImage:image forState:UIControlStateNormal];
                cellLanShou.contentShortBtn.contentUIView = cellLanShou.contentShortDetailView;
                cellLanShou.contentShortBtn.row = indexPath.section;
                [cellLanShou.contentShortBtn addTarget:self action:@selector(buttonPressedContent:) forControlEvents:UIControlEventTouchUpInside];
                cellLanShou.detailBackgroundBtn.contentUIView = cellLanShou.contentShortDetailView;
                [cellLanShou.contentDisplayShortBtn setTitle:@"  具体运费最终由实际配送里程决定" forState:UIControlStateNormal];
                cellLanShou.detailBackgroundBtn.isShortBtn = YES;
            }
            cellLanShou.detailBackgroundBtn.row = indexPath.section;
            [cellLanShou.detailBackgroundBtn addTarget:self action:@selector(buttonPressedDetail:) forControlEvents:UIControlEventTouchUpInside];
            if(2 == lQuickType)
            {
                cellLanShou.contentDetailView.hidden = YES;
                cellLanShou.contentShortDetailView.hidden = YES;
                cellLanShou.detailBackgroundBtn.hidden = YES;
                cellLanShou.detailBtn.hidden = YES;
            }
            else
            {
                cellLanShou.detailBackgroundBtn.hidden = NO;
                cellLanShou.detailBtn.hidden = NO;
                if((_iRow >= 0) && !_bHidden && (_iRow == indexPath.section))
                {
                    if(cellLanShou.detailBackgroundBtn.isShortBtn)
                    {
                        cellLanShou.contentShortDetailView.hidden = NO;
                        cellLanShou.contentDetailView.hidden = YES;
                    }
                    else
                    {
                        cellLanShou.contentShortDetailView.hidden = YES;
                        cellLanShou.contentDetailView.hidden = NO;
                    }
                }
                else
                {
                    cellLanShou.contentShortDetailView.hidden = YES;
                    cellLanShou.contentDetailView.hidden = YES;
                }

            }
            NSString *quickTypeIconUrl = [[[self.arratData  objectAtIndex:indexPath.section]valueForKey:@"courierRankIconUrl"] toString];
            [self loadIcon:cellLanShou.imageViewPeiSongDengJi withWayQuickTypeIconUrl:quickTypeIconUrl withTableViewcell:cellLanShou];

            quickTypeIconUrl = [[[self.arratData  objectAtIndex:indexPath.section]valueForKey:@"quickTypeIconUrl"] toString];
            [self loadOrderTypeIcon:cellLanShou.imageViewOrderType withWayQuickTypeIconUrl:quickTypeIconUrl withTableViewcell:cellLanShou];
            cell = cellLanShou;
        }
.
.
.
}
-(void)hiddenDetail
{
    if((nil == _contentHVView) || (_iRow < 0))
    {
        return;
    }
    if(!(_contentHVView.hidden))
    {
        _contentHVView.hidden = YES;

        _iRow = -1;
        _bHidden = YES;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self hiddenDetail];
    .
    .
    .
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:YES];
    self.imageViewIconIcon.hidden = YES;
    self.labelTitle.hidden = YES;
        self.buttonRightItem.hidden = YES;
    self.imageViewNavView.hidden = YES;
    _viewImageControlBG = nil;
    [self.remindLabel removeFromSuperview];
    [self hiddenDetail];
}

// 滚动时,触发该函数
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    [self hiddenDetail];
}


-(void)buttonPressedDetail:(UIButtonValue*)sender{

    if((nil == sender) || (nil == sender.contentUIView))
    {
        return;
    }
    sender.contentUIView.hidden = !(sender.contentUIView.hidden);
    if(!(sender.contentUIView.hidden))
    {

        if((nil != self.tableView) && (self.arratData.count > 0 ) && (sender.row < self.arratData.count) && (_iRow < self.arratData.count))
        {
            if((_iRow != sender.row) && (_iRow >= 0))
            {
                _contentSecondHVView = _contentHVView;
                _contentSecondHVView.hidden = YES;
                _contentHVView = sender.contentUIView;
                _contentHVView.hidden = NO;
                _iRow = sender.row;
                _bHidden = NO;
            }
            else
            {
                _iRow = sender.row;
                _contentHVView = sender.contentUIView;
                _contentHVView.hidden = NO;
                _bHidden = NO;
//                [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:sender.row]] withRowAnimation:UITableViewRowAnimationNone];
            }
        }
        else
        {
            _iRow = sender.row;
            _contentHVView = sender.contentUIView;
            _contentHVView.hidden = NO;
            _bHidden = NO;
        }

    }
    else
    {
        _contentHVView.hidden = YES;
        _iRow = -1;
        _bHidden = YES;

    }
}


-(void)buttonPressedContent:(UIButtonValue*)sender{

    if((nil == sender) || (nil == sender.contentUIView))
    {
        return;
    }
    if(!(sender.contentUIView.hidden))
    {
//        sender.contentUIView.hidden = YES;
        _contentHVView = sender.contentUIView;
//        [self.tableView reloadData];
        //跳转到运费模版页面
        FeeWebViewController *feeWebViewController = [[FeeWebViewController alloc] init];
        NSString *waybillIdStr = [[[self.arratData  objectAtIndex:sender.row]valueForKey:@"waybillId"] toString];
        if(waybillIdStr.length > 0)
        {
            feeWebViewController.waybillId = waybillIdStr;
            //        webViewController.type = WebViewTypePolicy;
            feeWebViewController.title = @"配送运费";
            [self.navigationController pushViewController:feeWebViewController animated:YES];
        }

    }
    else
    {
        sender.contentUIView.hidden = NO;
    }

}


相关实践学习
基于Hologres轻松玩转一站式实时仓库
本场景介绍如何利用阿里云MaxCompute、实时计算Flink和交互式分析服务Hologres开发离线、实时数据融合分析的数据大屏应用。
阿里云实时数仓实战 - 项目介绍及架构设计
课程简介 1)学习搭建一个数据仓库的过程,理解数据在整个数仓架构的从采集、存储、计算、输出、展示的整个业务流程。 2)整个数仓体系完全搭建在阿里云架构上,理解并学会运用各个服务组件,了解各个组件之间如何配合联动。 3&nbsp;)前置知识要求 &nbsp; 课程大纲 第一章&nbsp;了解数据仓库概念 初步了解数据仓库是干什么的 第二章&nbsp;按照企业开发的标准去搭建一个数据仓库 数据仓库的需求是什么 架构 怎么选型怎么购买服务器 第三章&nbsp;数据生成模块 用户形成数据的一个准备 按照企业的标准,准备了十一张用户行为表 方便使用 第四章&nbsp;采集模块的搭建 购买阿里云服务器 安装 JDK 安装 Flume 第五章&nbsp;用户行为数据仓库 严格按照企业的标准开发 第六章&nbsp;搭建业务数仓理论基础和对表的分类同步 第七章&nbsp;业务数仓的搭建&nbsp; 业务行为数仓效果图&nbsp;&nbsp;
目录
相关文章
|
8月前
|
Kubernetes 网络虚拟化 Perl
k8s常用的网络插件优化方案|干货
k8s常用的网络插件优化方案|干货
|
19天前
|
搜索推荐 安全 定位技术
产品服务功能特性
产品服务功能特性
28 3
|
19天前
|
存储 运维 数据库
不敢书面化的解决方案就不是好方案
不敢书面化的解决方案就不是好方案
|
11月前
|
SQL 存储 缓存
18种接口实用优化方案总结
18种接口实用优化方案总结
111 0
|
11月前
|
存储 缓存 JSON
聊聊方案中心性能优化中做的缓存设计
总结国际站方案中心物流运费计算性能优化过程中面临问题、问题分析、解决思路以及整体解决方案
聊聊方案中心性能优化中做的缓存设计
|
12月前
|
SQL 消息中间件 缓存
接口优化的常见方案实战总结
接口优化的常见方案实战总结
|
开发工具 Android开发
Android推送集成方案总结
刚做完推送集成方案,记录下坑。 这里记录的特性和使用时针对写blog时采用的sdk的,具体使用流程和限制还请参考官方给出的sdk. #### 1、推送规则 小米手机用小米推送; 华为手机用华为推送; 其他手机用友盟推送。
typescripet92-添加任务功能优化
typescripet92-添加任务功能优化
93 0
typescripet92-添加任务功能优化
|
SQL 前端开发 JavaScript
6款 Retool 最佳替代方案
本篇文章的目的通过低代码平台使用者的视角引出细节,了解他们为什么使用低代码平台以及会选择哪个低代码平台来加速内部系统的开发。
714 0
6款 Retool 最佳替代方案
|
SQL 缓存 测试技术
预告片优化方案
 看了一下代码,同时在线上做了观察压测。个人总结这个接口问题在于太过于依赖缓存,根本不会走DB。依赖缓存造成了依赖缓存的数据结构。首先要从缓存中取出一堆数据。而且要走两次,一次取正片的信息,一次取专辑内所有视频的信息。取出来的信息在CPU里计算筛选,排序。本身缓存取数据就比较快,再加上计算量大。其实我们并发量最大的api接口们都是采用这个模式设计的。调用的多了,我觉得我真是压测的狠的话,会造成CPU密集。其实现在的缓存之类的都可以持久化了,完全可以当数据库用。但是关系型数据作为一个长久的经典还有一个很重要的原因:保持一个IO和CPU使用的平衡。
预告片优化方案