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/ ...
随机推荐
- HashMap 数组应用面试题(Point)
今天看了一题面试题,以为很简单,不过自己写了遍,没有完全写出来: 题目是这样的: 给定一些 points 和一个 origin,从 points 中找到 k 个离 origin 最近的点.按照距离由小 ...
- 【渗透课程】第五篇-SQL注入的原理
哈哈哈,讲到注入了.我想给大家讲注入的原理.这个我们前面的前言篇就说过,所谓的SQL注入就是,绕过数据库验证机制直接执行SQL语句.怎么说呢,我们先讲一个概念吧! 网站和网页的区别 单纯的网页是静态的 ...
- 聊一聊Redis的数据结构
如果没有记错的话,应该是在两个月前把 我们经常看到此类的文章: Redis的五种数据结构 Redis的数据结构以及对应的使用场景 其实以数据结构这个词去说明Redis的String.Hash.List ...
- python基础教程(九)
python异常 python用异常对象(exception object)来表示异常情况.遇到错误后,会引发异常.如果异常对象并未被处理或捕捉,程序就会用所谓的 回溯(Traceback, 一种错误 ...
- 即时通信系统Openfire分析之四:消息路由
两个人的孤独 两个人的孤独,大抵是,你每发出去一句话,都要经由无数网络.由几百个计算机处理后,出在他的面前,而他就在你不远处. 连接管理之后 Openfire使用MINA网络框架,并设置Connect ...
- java.lang.reflect.MalformedParameterizedTypeException异常问题
做dubbo框架集成的时候,出现的问题,本来的原来的工程没有错误,引入dubbo后报错,原因是spring的jar文件冲突,我用的spring是4.x,dubbo引入的是2.5所以需要去掉,相关的po ...
- 转载 远程用户连接mysql授权
授权法: 在安装mysql的机器上运行: 1.d:\mysql\bin\>mysql -h localhost -u root //这样应该可以进入MySQL服务器 2.mysql> ...
- Spring定时任务quartz表达式
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp32 0 0 12 * * ?---------------在每天中午12: ...
- group by 详解
1.概述 2.原始表 3.简单Group By 4.Group By 和 Order By 5.Group By中Select指定的字段限制 6.Group By All 7.Group By与聚合函 ...
- 【★】致全球第一批全帧3D游戏!
图一 游戏片头 致逝去的青春记忆. 好久没人玩Ballance了吧,贴吧里貌似早已冷掉了. 作为一款经典游戏,Ballance的宣传却做得不到位,官方的介绍甚至没能展现出它的全部诱人之处.所以笔者决 ...