popOver 弹出框简单使用
1.仿QQ弹出框
1.1用到的知识点
1.1.1如何调整弹出框的大小(这里弹出的也是控制器)
这里已经有讲解过http://blog.csdn.net/iostiannan/article/details/51131431
1.1.2如何使QQ弹出框的文字与弹出框Frame自适应
```
此方法,会返回一个由UIKit子类调用后得到的Size ,此size即是完美适应调用此方法的UIKit子类的size
得到此size后, 可以调用 调整弹框大小的方法 **preferredContentSize**配合使用
```//重置本控制器的大小
-(CGSize)preferredContentSize{
if (self.popoverPresentationController != nil) {
CGSize tempSize ;
tempSize.height = self.view.frame.size.height;
tempSize.width = 155;
CGSize size = [_tableVIew sizeThatFits:tempSize]; //返回一个完美适应tableView的大小的 size
return size;
}else{
return [super preferredContentSize];
}
}
代码如下
viewController.m
#import "ViewController.h"
#import "PopViewController.h"
@interface ViewController ()<UIPopoverPresentationControllerDelegate>
{
PopViewController *_popVC;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.title = @"QQ";
self.view.backgroundColor = [UIColor whiteColor];
UIButton *btnR = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnR.frame = CGRectMake(0, 0, 50, 50);
btnR.backgroundColor = [UIColor clearColor];
[btnR setTitle:@"+" forState:UIControlStateNormal];
[btnR addTarget:self action:@selector(popView) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *imte = [[UIBarButtonItem alloc] initWithCustomView:btnR];
self.navigationItem.rightBarButtonItem = imte;
}
-(void)popView{
_popVC = [[PopViewController alloc] init];
_popVC.modalPresentationStyle = UIModalPresentationPopover;
//设置依附的按钮
_popVC.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItem;
//可以指示小箭头颜色
_popVC.popoverPresentationController.backgroundColor = [UIColor whiteColor];
//content尺寸
_popVC.preferredContentSize = CGSizeMake(400, 400);
//pop方向
_popVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
//delegate
_popVC.popoverPresentationController.delegate = self;
[self presentViewController:_popVC animated:YES completion:nil];
}
//代理方法 ,点击即可dismiss掉每次init产生的PopViewController
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
return UIModalPresentationNone;
}
弹出框类.m
<div class="se-preview-section-delimiter"></div>
#import "PopViewController.h"
@interface PopViewController ()<UITableViewDataSource,UITableViewDelegate>
{
UITableView *_tableVIew;
NSArray *_dataArray;
NSArray *_arr1;
NSArray *_arr2;
}
@end
@implementation PopViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
_arr1 = @[@"扫一扫",@"加好友",@"创建讨论组",@"发送到电脑",@"面对面快传",@"收钱"];
_arr2 = @[@"right_menu_QR",@"right_menu_addFri",@"right_menu_multichat",@"right_menu_sendFile",@"right_menu_facetoface",@"right_menu_payMoney"];
_tableVIew = [[UITableView alloc] initWithFrame:self.view.bounds];
_tableVIew.delegate = self;
_tableVIew.dataSource = self;
_tableVIew.scrollEnabled = YES;
_tableVIew.backgroundColor = [UIColor whiteColor];
[self.view addSubview:_tableVIew];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _arr2.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *str = @"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
}
cell.textLabel.text = _arr1[indexPath.row];
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",_arr2[indexPath.row]]];
return cell;
}
//重置本控制器的大小
-(CGSize)preferredContentSize{
if (self.popoverPresentationController != nil) {
CGSize tempSize ;
tempSize.height = self.view.frame.size.height;
tempSize.width = 155;
CGSize size = [_tableVIew sizeThatFits:tempSize]; //返回一个完美适应tableView的大小的 size
return size;
}else{
return [super preferredContentSize];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
GitHUb===>>https://github.com/tianNanYiHao/MyTestDemo.git
popOver 弹出框简单使用的更多相关文章
- Bootstrap popover弹出框
popover被挤压.遮挡的问题: 弹出框显示的时候如果贴近一个列的边沿,就会很窄或被遮挡,解决起来很简单,只需在初始化的时候添加一个container属性就可以了: $(function (){ $ ...
- js简单显示和隐藏div,触发超链接,动态更改button值,setInterval()简单使用,jquery easyui弹出框简单使用 .
js简单显示和隐藏div .<!DOCTYPE html> .<html> .<head> .<meta charset="UTF-8"& ...
- php中bootstrap框架.popover弹出框,鼠标移动到上面自动显示,离开自动消失
<div rel="name"></div> <script> $(function(){//显示弹出框 $("[rel=name]& ...
- popover弹出框
<style> #view{width: 300px;height: 200px;border: 1px solid red;} </style> 以上是为了viewport更 ...
- Django:popup弹出框简单应用实例
效果:在p1.html页面点击,弹出p2的弹出框,填写数据,在 popup_response页面处理数据 1.url设置 urlpatterns = patterns( url(r'^p1.html' ...
- Popover 弹出框
基础用法 Popover 的属性与 Tooltip 很类似,它们都是基于Vue-popper开发的,因此对于重复属性,请参考 Tooltip 的文档,在此文档中不做详尽解释. 设置索引ref,在按钮中 ...
- Popover 弹出框 设置top,显示有时是向下的,解决方式
参数里面有个popper-options,官网给的值是{boundariesElement: 'body', gpuAcceleration: false },将这个加上问题就解决了.
- element-UI动态的循环生成Popover弹出框的方法
父组件:<div class="itemLi" :class="{gray: (salse.flashsaleStatus==3 || salse.flashsal ...
- bootstrap中popover.js(弹出框)使用总结+案例
bootstrap中popover.js(弹出框)使用总结+案例 *转载请注明出处: 作者:willingtolove: http://www.cnblogs.com/willingtolove/p/ ...
随机推荐
- chrome开发工具指南(二)
Application 面板 使用 App Manifest 窗格检查您的网络应用清单和触发 Add to Homescreen 事件. 使用 Service Worker 窗格执行与服务工作线程相关 ...
- 比较两个date返回日期相差天数
public static int daydiff(Date fDate, Date oDate) { Calendar aCalendar = Calendar.getInstance(); aCa ...
- Linux-使用patch命令给uboot打补丁(3)
patch:修改文件,让用户对原文件打补丁 用法 patch -p[剥离层级] <[补丁文件] 打补丁示例: u-boot-1.1.6_jz2440.patach补丁文件给u-b ...
- FPGA学习:VHDL设计灵活性&不同设计思路比较
概要 由于VHDL编程实现数字电路具有很高的灵活性,为多种不同的思路编写实现同一种功能提供了可能.这些不同的设计思路,在耗费资源,可靠性,速度上也有很大的差异,往往需要我们根据实际需求和资源条件选择适 ...
- jenkins+gitlab+sonar+testng构建持续集成测试环境(配置干货篇)
几个工具的安装部分就不在此介绍了! jenkins配置: 1.插件安装 2.root私钥配置 3.构建job配置 4.部署job配置 5.测试job配置 7.jenkins全局工具配置 8.jenki ...
- unity(Exploder插件)研究
哎 好久没写博客了 不是因为最近忙 而是比较懒 学的东西不深入 前段时间发现一个很好用的插件叫Exploder(是一个可以制作任何物体的爆炸效果) 好!我们开始我们的炸学校旅程!(O(∩_∩)O哈哈~ ...
- Alpha阶段-个人总结
一.五个问题 1.第三章中提到了"质量"和"按时交付"的问题,我想问,世事难料,当两者不能兼得的时候,我是保证质量却无法按时交付,还是水两下保证按时交付呢? 2 ...
- java记事本1.2版
功能:实现了新建,打开,保存,退出,复制,剪切,粘贴等功能 效果图:
- 团队作业8——Beta项目(冲刺计划)
Beta阶段冲刺计划 经过几周的努力我们完成了Alpha的开发,进过一段时间的调整与重组我们继续向Beta版进发. 1. 新成员介绍 林乔桦(201421123074):掌握c语言,JavaScrip ...
- 团队作业4——第一次项目冲刺(Alpha版本)2017.4.26
2017.04.26 天气热. 时间:上午 9:35 ---10:10分 地点:陆大304实验室 会议内容:今天将昨天的的一些问题进行了讨论,以及针对助教提出的问题进行了分析,是因为我们昨天经过讨论后 ...