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. Struts:文件上传下载

  2. [2014-12-29]使用Enum位模式进行多重状态(或权限)管理

    前言 对于Enum在AspNet Mvc中的应用,我之前提到一种扩展,如何在 Asp.net Mvc 开发过程中更好的使用Enum.这里将介绍另一种更好的使用Enum的方法. Enum定义 以一个代表 ...

  3. AVAssetWriter 硬编码bug解决

    一.需求 直播助手在录屏过程中,产品要求跟随用户手机屏幕旋转,录屏的视频跟随旋转 二.实施方案 目前触手录,iTools PC端均已经实现该功能,并且该功能只适配iOS9和iOS10系统.猜测实现方案 ...

  4. 解决MVC模式文件下载附件中文名称乱码

    解决如下: 进行url编码:Server.UrlPathEncode(file.AttachmentName) return File(file.TempWorkPath, CommonTools.G ...

  5. 第4阶段——制作根文件系统之编译配置安装busybox(3)

    在上一节分析出制作一个最小的根文件系统至少需要: (1)/dev/console(终端控制台, 提供标准输入.标准输出以及标准错误) /dev/null  (为空的话就是/dev/null, 所有写到 ...

  6. ASP.NET Core Web服务器 Kestrel和Http.sys 特性详解

    ASP.NET Core Web服务器 Kestrel和Http.sys 特性详解 1.1. 名词解释 1.2. Kestrel基本工作原理 1.2.1. Kestrel的基本架构 1.2.2. Ke ...

  7. 定时任务之crontab命令

    1.简介 crontab用于设置周期性被执行的命令 Linux系统中Linux调动工作分为两大类: 1.系统执行的工作:系统周期性所要执行的工作,如备份系统数据.清理缓存 2.个人执行的工作:某个用户 ...

  8. java记事本1.2版

    功能:实现了新建,打开,保存,退出,复制,剪切,粘贴等功能 效果图:

  9. 第二次项目冲刺(Beta阶段)--第二天

    一.站立式会议照片 二.项目燃尽图 三.项目进展 功能模块的代码编写完成,界面布局规划已经定型,不会有大的修改,接下去就是主要解决存在的bug以及各种测试. 队员  ID 贡献比 王若凡 201421 ...

  10. 201521123064 《Java程序设计》第4周学习总结

    1. 本章学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. ① 以上周PTA实验"形状"为例,Circle类和Rectangle类中 ...