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/ ...
随机推荐
- Atomic类和CAS
说Atomic类之前,先聊一聊volatile. 对volatile的第一印象就是可见性.所谓可见性,就是一个线程对共享变量的修改,别的线程能够感知到. 但是对于原子性,volatile是不能保证的. ...
- Windows下JNI的使用教程
JNI的使用大致有以下4个步骤: 一.在Java中写native方法 二.用javah命令生成C/C++头文件 三.写对应的C/C++程序实现头文件中声明的方法,并编译成库文件 四.在Java中加载这 ...
- Python学习笔记6
raw_input 与 input 使用input和raw_input都可以读取控制台的输入,但是input和raw_input在处理数字时是有区别的 当输入为纯数字时 input返回的是数值类型,如 ...
- JRE 和 JDK 的区别
JRE顾名思义是java运行时环境,包含了java虚拟机,java基础类库.是使用java语言编写的程序运行所需要的软件环境,是提供给想运行java程序的用户使用的. JDK顾名思义是java开发 ...
- docker 添加国内源
docker for mac 获取地址:dao镜像地址  # 163的地址 https://hub-mirror.c.163.com docker for mac的设置操作:   点击Apply ...
- Visual Studio2017 远程调试 Remote Debugger
前言 大家在使用vs打包后的文件部署到服务器后,有时候我们需要对线网的后台进行调试.但是它不像在VS中.这个时候我们该怎么调试呢? 微软想到了这一点,他们在 VS 中给我们提供了一个功能: Remot ...
- Java之JMX 详解
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt194 一.JMX简介 JMX是一种JAVA的正式规范,它主要目的是让程序有被 ...
- POJ 2449 Dijstra + A* K短路
这题一开始的思路应该是直接从源点进行BFS搜索K短路. 但这样的复杂度在点数和K的值增大后将会变得很大. 而A*算法则构造一个h(x),在进行BFS时,每次都抛出最小的h(x)从而使汇点的出队速度加快 ...
- 第二次项目冲刺(Beta阶段)5.22
1.提供当天站立式会议照片一张 会议内容: ①检查前一天的任务情况,将遇到的困难反馈.解决. ②制定新一轮的任务计划. 2.每个人的工作 (1)工作安排 队员 今日进展 明日安排 王婧 #53(完成) ...
- 个人作业3——个人总结(Alphe)
小结: 1.软件工程的第一阶段终于结束了,说实话,每个人的课程都很紧张,在这么紧张的时期我们都每周抽出一些时间来开个小会总结或者计划软件工程的相关任何非常难得,大家的态度都诚恳认真,我亦是如此,只是我 ...