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

 
源码下载 ==>> GitHUb

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 弹出框简单使用的更多相关文章

  1. Bootstrap popover弹出框

    popover被挤压.遮挡的问题: 弹出框显示的时候如果贴近一个列的边沿,就会很窄或被遮挡,解决起来很简单,只需在初始化的时候添加一个container属性就可以了: $(function (){ $ ...

  2. js简单显示和隐藏div,触发超链接,动态更改button值,setInterval()简单使用,jquery easyui弹出框简单使用 .

    js简单显示和隐藏div .<!DOCTYPE html> .<html> .<head> .<meta charset="UTF-8"& ...

  3. php中bootstrap框架.popover弹出框,鼠标移动到上面自动显示,离开自动消失

    <div rel="name"></div> <script> $(function(){//显示弹出框 $("[rel=name]& ...

  4. popover弹出框

    <style> #view{width: 300px;height: 200px;border: 1px solid red;} </style> 以上是为了viewport更 ...

  5. Django:popup弹出框简单应用实例

    效果:在p1.html页面点击,弹出p2的弹出框,填写数据,在 popup_response页面处理数据 1.url设置 urlpatterns = patterns( url(r'^p1.html' ...

  6. Popover 弹出框

    基础用法 Popover 的属性与 Tooltip 很类似,它们都是基于Vue-popper开发的,因此对于重复属性,请参考 Tooltip 的文档,在此文档中不做详尽解释. 设置索引ref,在按钮中 ...

  7. Popover 弹出框 设置top,显示有时是向下的,解决方式

    参数里面有个popper-options,官网给的值是{boundariesElement: 'body', gpuAcceleration: false },将这个加上问题就解决了.

  8. element-UI动态的循环生成Popover弹出框的方法

    父组件:<div class="itemLi" :class="{gray: (salse.flashsaleStatus==3 || salse.flashsal ...

  9. bootstrap中popover.js(弹出框)使用总结+案例

    bootstrap中popover.js(弹出框)使用总结+案例 *转载请注明出处: 作者:willingtolove: http://www.cnblogs.com/willingtolove/p/ ...

随机推荐

  1. Maven详解(五)------ 坐标的概念以及依赖管理

    我们知道maven能帮我们管理jar包,那么它是怎么管理的呢?这篇博客我们来详细介绍. 1.什么是坐标? ①.数学中的坐标 在平面上,使用 X .Y 两个向量可以唯一的定位平面中的任何一个点 在空间中 ...

  2. Linux入门练习

    1.echo是用于终端打印的基本命令: 1.1echo默认将一个换行符追加到输出文本的尾部. 1.2 echo中转义换行符 如需使用转义序列,则采用echo -e "包含转义序列的字符串&q ...

  3. SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis

    原博主链接:( http://blog.csdn.net/zhshulin ) 使用 SSM ( Spring . SpringMVC 和 Mybatis )已经有三个多月了,项目在技术上已经没有什么 ...

  4. [2016-07-15]nuget包管理器控制台下的powershell脚本介绍

    博客有阵子没打理了,今天刚恢复样式,但是标题还是不太正常,总算能凑合看看. 回到正题,最近为了能在VS的程序包管理器控制台上能方便的自定义ps脚本去调整project的package,就开始看powe ...

  5. [2014-12-30]如何动态构造Lambda表达式(动态构造Lambda查询条件表达式)

    声明 本文对Lambda表达式的扩展,示例代码来源于网络. 场景描述 web开发查询功能的时候,如果查询条件比较多,就会遇到动态组合查询条件的情况.在手写sql的情况下,我们一般会根据传入的参数,针对 ...

  6. js事件汇总

    常用事件: 1.鼠标事件:onClick,onDblClick,onMouseDown,onMouseUp,onMouseOut,onMouseOver ·onClick:单击页面元素时发生,onDb ...

  7. 自己为什么注册博客(csdn讲师:Array)

    记录生活,记录技术,记录青春. 势若在己,则人力可以至:势若在人,则忧心亦无益. 倘若势不在己,该怎么办? 天下之势,本如流水.若流于他处,则处心积虑,断流开源,独占大势. 这是一个最好的时代,也是一 ...

  8. 一个小时学会Git

    一.版本控制概要 Git 是一种在全球范围都广受欢迎的版本控制系统.在开发过程中,为了跟踪代码,文档,项目等信息中的变化,版本控制变得前所未有的重要.但跟踪变化远远不能满足现代软件开发行业的协同需求, ...

  9. 垃圾收集器Serial 、Parallel、CMS、G1

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt378 这里介绍4个垃圾收集器,如果进行了错误的选择将会大大的影响程序的性能. ...

  10. WeTest+微信:小程序云端测试系统上线

    日前,微信新增小程序测试系统,可便于开发者检测小程序缺陷,评估小程序产品质量.在小程序发布之前,开发者可将小程序代码提交到测试系统,在不同型号的手机真机上运行,执行完毕后自动生成测试报告.小程序云端测 ...