上图看效果先:

1)画座位图其实不是很难一般数据都会给坐标,将坐标对应座位画出来就可以了,主要是开场动画要设置默认大小,还有座位图的数量也不是固定的,所以在初始化座位图的时侯就默认算出了整个座位图的大小

-(instancetype)initWithSeatsArray:(NSMutableArray *)seatsArray maxNomarWidth:(CGFloat)maxW seatBtnActionBlock:(void (^)(id))actionBlock{          
   if (self = [super init]) {                  
       self.actionBlock = actionBlock;                  
       ZFSeatsModel *seatsModel = seatsArray.firstObject;        
                NSUInteger cloCount = [seatsModel.columns count];                  
                if (cloCount % 2) cloCount += 1;//偶数列数加1 防止中线压住座位                  
                CGFloat seatViewW = maxW - 2 * ZFseastsRowMargin;                  
                CGFloat seatBtnW = seatViewW / cloCount;                  
                if (seatBtnW > ZFseastMinW_H) {            
                    seatBtnW = ZFseastMinW_H;            
                    seatViewW = cloCount * ZFseastMinW_H;        
                }        
                //初始化就回调算出按钮和自身的宽高        
                CGFloat seatBtnH = seatBtnW;        
                self.seatBtnWidth = seatBtnW;        
                self.seatBtnHeight = seatBtnH;        
                self.seatViewWidth = seatViewW;        
                self.seatViewHeight = [seatsArray count] * seatBtnH;        
                //初始化座位        
                [self initSeatBtns:seatsArray];    
            }    
            return self;
        }

2)画侧边的索引条 主要就是算出总共有多少列,有没走到之类的 将座位列号根据每个竖向坐标直接画进索引条就可以了

//画索引条
- (void)drawRect:(CGRect)rect {          
   NSDictionary *attributeName = @{NSFontAttributeName: [UIFont systemFontOfSize:10],NSForegroundColorAttributeName : [UIColor whiteColor]};    
        CGFloat NuomberTitleH = (self.height - 2 * 10) / self.indexsArray.count;          
        [self.indexsArray enumerateObjectsUsingBlock:^(ZFSeatsModel *seatsModel, NSUInteger idx, BOOL *stop) {                      
                CGSize strsize =  [seatsModel.rowId sizeWithAttributes:attributeName];            
                [seatsModel.rowId drawAtPoint:CGPointMake(self.width * 0.5 - strsize.width  * 0.5,10 + idx * NuomberTitleH + NuomberTitleH  * 0.5 - strsize.height  * 0.5) withAttributes:attributeName];              
          }];
    }

3)中线启示也是自定义一个view画一条线线上是label,每次随座位图上下滚动,重新设置自身高度重绘该线条就能达到效果

-(void)setHeight:(CGFloat)height{          
   [super setHeight:height];    
        [self setNeedsDisplay];
    }
    - (void)drawRect:(CGRect)rect {          
        CGContextRef context = UIGraphicsGetCurrentContext();    
        CGContextSetLineWidth(context, 1.0);    
        CGContextSetStrokeColorWithColor(context, [UIColor darkGrayColor].CGColor);    
        CGFloat lengths[] = {6,3};    
        CGContextSetLineDash(context, 0, lengths,2);    
        CGContextMoveToPoint(context, 0, 0);    
        CGContextAddLineToPoint(context, 0, self.bounds.size.height);    
        CGContextStrokePath(context);
    }

4)每次座位图滚动的时候随着偏移量的变化更新其他所有控件的坐标就能达到某一方向跟随scrollview滚动方向移动

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{    
   // 更新applogo    
   if (scrollView.contentOffset.y <= scrollView.contentSize.height - self.height +ZFseastsColMargin + 15) {        
       self.maoyanLogo.y = CGRectGetMaxY(self.seatView.frame) + 35;        
       self.maoyanLogo.centerX = self.seatView.centerX;    
   }else{        
       self.maoyanLogo.centerX = self.seatView.centerX;        
       self.maoyanLogo.y = scrollView.contentOffset.y + self.height - self.maoyanLogo.height;    
   }    
   //更新hallLogo    
   self.hallLogo.y = scrollView.contentOffset.y;          
   //更新中线    
   self.centerLine.height = CGRectGetMaxY(self.seatView.frame) + 2 * ZFSmallMargin;          
   if (scrollView.contentOffset.y < - ZFseastsColMargin ) {        
       self.centerLine.y = self.seatView.y - ZFseastsColMargin + ZFCenterLineY;    
   }else{        
       self.centerLine.y = scrollView.contentOffset.y + ZFCenterLineY;        
       self.centerLine.height = CGRectGetMaxY(self.seatView.frame) - scrollView.contentOffset.y - 2 * ZFCenterLineY + ZFseastsColMargin;    
   }    
   // 更新索引条    
   self.rowindexView.x = scrollView.contentOffset.x + ZFseastMinW_H;              
   //更新indicator大小位置    
   [self.indicator updateMiniIndicator];    
   if (!self.indicator.hidden || self.seatScrollView.isZoomBouncing)return;    
   self.indicator.alpha = 1;    
   self.indicator.hidden = NO;      
}

最后不多解释啦上Github地址:https://github.com/ZFbaby/ZFSeatsSelection/blob/master/ZFSeatsSelection

原文地址:http://www.cocoachina.com/ios/20160812/17347.html

高仿猫眼电影选座(选票)模块-b的更多相关文章

  1. android:自己定义组合控件Weight(高仿猫眼底部菜单条)

    在我们实际开发其中.会碰见一些布局结构类似或者同样的界面.比如应用的设置界面.tabbutton界面等. 这时候.对于刚開始学习的人来说,xml里面一个个绘制出来也许是最初的想法.可能随着经验的积累, ...

  2. android 自定义view之选座功能

    效果图: 界面比较粗糙,主要看原理. 这个界面主要包括以下几部分 1.座位 2.左边的排数 3.左上方的缩略图 4.缩略图中的红色区域 5.手指移动时跟随移动 6.两个手指缩放时跟随缩放 主要技术点 ...

  3. 基于socket.io的实时在线选座系统

    基于socket.io的实时在线选座系统(demo) 前言 前段时间公司做一个关于剧院的项目,遇到了这样一种情况. 在高并发多用户同时选座的情况下,假设A用户进入选座页面,正在选择座位,此时还没有提交 ...

  4. 模仿猫眼电影App一个动画效果

    看真正的猫眼效果图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzIxMDYyMA==/font/5a6L5L2T/fontsize/400/f ...

  5. 自己定义ViewpagerIndicator (仿猫眼,加入边缘回弹滚动效果)

    一.概述 今天主要来分享个自己定义viewpagerindicator.效果主要是仿 猫眼电影 顶部的栏目切换.也就是我们常说的indicator,难度简单,为了让滑动时效果更炫酷,我在滑动到左边第一 ...

  6. iOS开发之功能模块--高仿Boss直聘的常用语的开发

    首先上Boss直聘的功能界面截图,至于交互请读者现在Boss直聘去交互体验:     本人的公司项目要高仿Boss直聘的IM常用语的交互功能,居然花费了我前后17个小时完成,这回自己测试了很多遍,代码 ...

  7. android高仿微信拍照、多选、预览、删除(去除相片)相冊功能

    先声明授人与鱼不如授人与渔,仅仅能提供一个思路,当然须要源代码的同学能够私下有偿问我要源代码:QQ:508181017 工作了将近三年时间了,一直没正儿八经的研究系统自带的相冊和拍照,这回来个高仿微信 ...

  8. Qt编写高仿苹果MAC电脑输入法(支持触摸滑动选词)

    最近有个朋友找我定制一个输入法,需要高仿一个苹果MAC电脑的输入法,MAC操作系统的审美无疑是相当棒的,于是乎直接拿以前的输入法高仿了一个,由于之前有做过输入法这块的开发,而且改进了四年,各种需求都遇 ...

  9. 【饿了么】—— Vue2.0高仿饿了么核心模块&移动端Web App项目爬坑(三)

    前言:接着上一篇项目总结,这一篇是学习过程记录的最后一篇,这里会梳理:评论组件.商家组件.优化.打包.相关资料链接.项目github地址:https://github.com/66Web/ljq_el ...

随机推荐

  1. MSP430常见问题之IO端口类

    Q1:请问430 的I/O 中断能不能可靠的响应60ns 的脉冲信号, 就是来了一个60ns 的脉冲,430 的中断会有丢失吗?A1:端口支持的最高8M的时钟,无法响应这么快的频率. Q2:430是3 ...

  2. saltstack实战3--配置管理之grains

    grains是什么 grains是minion服务启动后,采集的客户端的一些基本信息,硬件信息,软件信息,网络信息,软件版本等.你可以在minion上自定义一些grains信息. 它是静态的信息,mi ...

  3. codevs4373 窗口==poj2823 Sliding Window

    Sliding Window Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 53676   Accepted: 15399 ...

  4. Tomcat - DBCP 配置

    1. Database configuration Create a new test user, a new database and a single test table. Your MySQL ...

  5. Linux 命令 - ps: 显示当前进程的快照

    命令格式 ps [options] 实例 a) 查看所有的进程. huey@huey-K42JE:~$ ps aux | head USER PID %CPU %MEM VSZ RSS TTY STA ...

  6. django 学习-2 模板

    如何使用渲染模板的方法来显示内容. 1.创建一个项目dream django-admin.py   startproject   dream cd  dream    再创建一个应用 python m ...

  7. Python基础-简单输出

    很好的一个博客地址:http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014316 ...

  8. Objective-C 【在手动内存管理中如何写set方法】

    ------------------------------------------- set方法的内存管理 代码: #import <Foundation/Foundation.h> @ ...

  9. Unity连接本地数据库sqlite

    首先要创建一个sqlite的数据库,记住文件地址,拷贝到Assets目录下,创建的数据库文件后缀为.sqlite.具体创建方法百度sqlite 然后百度Mono.Data.Sqlite,这是一个dll ...

  10. OC11_自动释放池

    // // Dog.h // OC11_自动释放池 // // Created by zhangxueming on 15/6/18. // Copyright (c) 2015年 zhangxuem ...