实现下拉弹出视图和Block的简单实现
实现效果如下:


实现代码如下:
@interface ViewController ()<UIViewControllerTransitioningDelegate>
{
UILabel *optionLabel; //显示选中值得label
BOOL isPresentingOrDismissingOption;
UIView *buildingOptionView; //选择的视图
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
buildingOptionView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
[self.view addSubview:buildingOptionView];
buildingOptionView.backgroundColor = [UIColor redColor];
buildingOptionView.layer.cornerRadius = ;
buildingOptionView.clipsToBounds = YES;
UIGestureRecognizer *tapOnBuildingOpetionView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnBuildingOpetionView:)];
[buildingOptionView addGestureRecognizer:tapOnBuildingOpetionView];
optionLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , buildingOptionView.width - , )];
optionLabel.text = @"第一教学楼";
[buildingOptionView addSubview:optionLabel];
optionLabel.textColor = [UIColor blackColor];
UIImageView *arrowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(optionLabel.right + ,optionLabel.top + ,,)];
arrowImageView.image = [UIImage imageNamed:@"classroom_arrow_icon"];
[buildingOptionView addSubview:arrowImageView];
}
//手势触发方法
- (void)tapOnBuildingOpetionView:(UITapGestureRecognizer *)tap{
NSLog(@"列表选择");
//弹出选择列表
OptionTableView *optionView = [[OptionTableView alloc]initWithFrame:CGRectMake(buildingOptionView.left + ,buildingOptionView.bottom + ,,) style:UITableViewStylePlain];
optionView.buildingsArray = @[@"第一教学楼", @"第二教学楼", @"第三教学楼", @"第四教学楼", @"第五教学楼", @"第六教学楼", @"第七教学楼", @"第八教学楼"];
[self.view addSubview:optionView];
//block的实现,给label赋值
[optionView setDismissOnBuilding:^(NSString *selectedBuilding) {
optionLabel.text = selectedBuilding;
}];
}
OptionTableView的实现代码如下:
#import <UIKit/UIKit.h> @interface OptionTableView : UITableView<UITableViewDataSource,UITableViewDelegate> @property (nonatomic, strong) NSArray *buildingsArray;
@property (nonatomic, copy) void (^dismissOnBuilding)(NSString *building); @end
static NSString *const buildingOptionCellId = @"Cell"; @interface OptionTableView () @end
@implementation OptionTableView - (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{ self = [super initWithFrame:frame style:style];
if (self) { self.dataSource = self;
self.delegate = self; [self registerClass:[UITableViewCell class] forCellReuseIdentifier:buildingOptionCellId];
self.backgroundColor = [UIColor blueColor]; }
return self; } #pragma mark - Table view dataSource //行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{ return self.buildingsArray.count; } //创建单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:buildingOptionCellId forIndexPath:indexPath];
cell.textLabel.text = self.buildingsArray[indexPath.row];
return cell; } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //block实现选中的值的传递 if (self.dismissOnBuilding) {
self.dismissOnBuilding(self.buildingsArray[indexPath.row]);
} //当选择完毕表视图收起
self.frame = CGRectZero;
}
写的不好,有更好的方法,欢迎大家告诉我,谢谢!!!
实现下拉弹出视图和Block的简单实现的更多相关文章
- iOS开发——UI篇&下拉弹出列表选择项效果
下拉弹出列表选择项效果 右边菜单中的按键,点击弹出一个列表可选择,选择其中一个,响应相应的事件并把文字显示在右边的菜单上:弹出下拉效果使用LMDropdownView插件,可以用POD进行加载pod ...
- 【Bootstrap3.0建站笔记二】button可下拉弹出层
1.button可下拉弹出层: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hpbmFwbGFu/font/5a6L5L2T/fontsize/400 ...
- CCOMBOX下拉弹出框,因属性对话框自动隐藏而弹出框没有隐藏问题
关于这个问题是可以使用 使其失去焦点 releasecapture()解决的,但是鼠标在下拉列表中的item中经过时,调用releasecapture()后会选中最后mousemove过的item项. ...
- android下拉弹出动画
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http:// ...
- IOS弹出视图 LewPopupViewController
LewPopupViewController是一款IOS弹出视图软件.iOS 下的弹出视图.支持iPhone/iPad. 软件截图 使用方法 弹出视图 1 2 3 4 5 PopupView *vie ...
- 弹性ScrollView,和下啦刷新的效果类似 实现下拉弹回和上拉弹回
今天做了一个弹性ScrollView,和下啦刷新的效果类似,我想这个很多需求都用的这种效果 其实这是一个自定义的scrollView,上代码,这是我写在一个公共的组件包里的 package com.p ...
- iOS实现自定义的弹出视图(popView)
前段时间,在项目中有个需求是支付完成后,弹出红包,实现这么一个发红包的功能.做了最后,实现的效果大致如下: 一.使用方法 整个ViewController的代码大致如下 // // SecondVi ...
- 弹性ScrollView,和下啦刷新的效果相似 实现下拉弹回和上拉弹回
今天做了一个弹性ScrollView,和下啦刷新的效果类似,我想这个非常多需求都用的这样的效果 事实上这是一个自己定义的scrollView,上代码.这是我写在一个公共的组件包里的 package c ...
- php网页,想弹出对话框, 消息框 简单代码
php网页,想弹出对话框, 消息框 简单代码 <?php echo "<script language=\"JavaScript\">alert(\&q ...
随机推荐
- redis 与 序列化
概念 序列化:把对象转化为可传输的字节序列过程称为序列化. 反序列化:把字节序列还原为对象的过程称为反序列化. 为什么需要序列化 序列化最终的目的是为了对象可以跨平台存储,和进行网络传输.而我们进行跨 ...
- 预定义的基础类型转换,BitConverter,BitArray
一.BitConverter 将预定义的基础类型与字节数据进行互转 1.将值类型转成字节数组(Unicode):BitConverter.GetBytes() byte[] data = BitCon ...
- RedisTemplate和StringRedisTemplate的区别
今天springboot项目中用redis的时候,遇到了一个问题,用RedisTemplate这个类向redis中存储数据的时候,明明数据存进去了,也可以取出来,但是rdm就是看不到key的值,网上的 ...
- 哇!吐槽!oh shit
一个jsp写了5000行,我尼玛醉了,看晕了-2017年10月12日10:19:40
- CentOS7.x安装nodejs-10.16.3
Wiki.js 安装 需要用到nodejs,本文介绍下快速安装nodejs 环境: 操作系统:CentOS7.6 nodejs版本:10.16.3 官网:https://nodejs.org/en/ ...
- 利用JS对象把值传到后台
记得以前刚写asp.net 从前台往后台传值 都是var data=A,B,C,D,E; 循环添加用逗号隔开 后台还要被测试测出只输入,就错了 哈哈..后来用✈◆类似的符号隔开 不是长久之计... 现 ...
- 006_软件安装之_Proteus 8.6 SP2 Professional
安装好像已经是直接破解的版本了 链接:https://pan.baidu.com/s/1NQDFJeJwmzoMIPZWhWNtFA提取码:ql8g 复制这段内容后打开百度网盘手机App,操作更方便哦
- bootstrap-wysihtml5 ckeditor 修改富文本编辑器可以上传图片
bootstrap-wysihtml5 ckeditor 修改富文本编辑器可以上传图片 bootstrap-wysihtml5实际使用内核为ckeditor 故这里修改ckeditor即可 ...
- 063_显示本机 Linux 系统上所有开放的端口列表
#!/bin/bash#从端口列表中观测有没有没用的端口,有的话可以将该端口对应的服务关闭,防止意外的攻击可能性 ss -nutlp |awk '{print $1,$5}' | awk -F&quo ...
- python打包成exe,太大了该怎么解决?
这是一个很长的故事,嫌长的直接看最后的结论 事情经过 上周接了个需求,写了个小工具给客户,他要求打包成exe文件,这当然不是什么难事.因为除了写Python的,绝大多数人电脑里都没有Python编译器 ...