1.仿QQ弹出框

1.1用到的知识点

1.1.1如何调整弹出框的大小(这里弹出的也是控制器)

这里已经有讲解过http://blog.csdn.net/iostiannan/article/details/51131431

1.1.2如何使QQ弹出框的文字与弹出框Frame自适应
  1. ```
  2. 此方法,会返回一个由UIKit子类调用后得到的Size ,此size即是完美适应调用此方法的UIKit子类的size
  3. 得到此size后, 可以调用 调整弹框大小的方法 **preferredContentSize**配合使用
  4. ```//重置本控制器的大小
  5. -(CGSize)preferredContentSize{
  6. if (self.popoverPresentationController != nil) {
  7. CGSize tempSize ;
  8. tempSize.height = self.view.frame.size.height;
  9. tempSize.width = 155;
  10. CGSize size = [_tableVIew sizeThatFits:tempSize]; //返回一个完美适应tableView的大小的 size
  11. return size;
  12. }else{
  13. return [super preferredContentSize];
  14. }
  15. }

代码如下

viewController.m

  1. #import "ViewController.h"
  2. #import "PopViewController.h"
  3. @interface ViewController ()<UIPopoverPresentationControllerDelegate>
  4. {
  5. PopViewController *_popVC;
  6. }
  7. @end
  8. @implementation ViewController
  9. - (void)viewDidLoad {
  10. [super viewDidLoad];
  11. // Do any additional setup after loading the view, typically from a nib.
  12. self.navigationItem.title = @"QQ";
  13. self.view.backgroundColor = [UIColor whiteColor];
  14. UIButton *btnR = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  15. btnR.frame = CGRectMake(0, 0, 50, 50);
  16. btnR.backgroundColor = [UIColor clearColor];
  17. [btnR setTitle:@"+" forState:UIControlStateNormal];
  18. [btnR addTarget:self action:@selector(popView) forControlEvents:UIControlEventTouchUpInside];
  19. UIBarButtonItem *imte = [[UIBarButtonItem alloc] initWithCustomView:btnR];
  20. self.navigationItem.rightBarButtonItem = imte;
  21. }
  22. -(void)popView{
  23. _popVC = [[PopViewController alloc] init];
  24. _popVC.modalPresentationStyle = UIModalPresentationPopover;
  25. //设置依附的按钮
  26. _popVC.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItem;
  27. //可以指示小箭头颜色
  28. _popVC.popoverPresentationController.backgroundColor = [UIColor whiteColor];
  29. //content尺寸
  30. _popVC.preferredContentSize = CGSizeMake(400, 400);
  31. //pop方向
  32. _popVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
  33. //delegate
  34. _popVC.popoverPresentationController.delegate = self;
  35. [self presentViewController:_popVC animated:YES completion:nil];
  36. }
  37. //代理方法 ,点击即可dismiss掉每次init产生的PopViewController
  38. -(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
  39. return UIModalPresentationNone;
  40. }


弹出框类.m

  1. <div class="se-preview-section-delimiter"></div>
  2. #import "PopViewController.h"
  3. @interface PopViewController ()<UITableViewDataSource,UITableViewDelegate>
  4. {
  5. UITableView *_tableVIew;
  6. NSArray *_dataArray;
  7. NSArray *_arr1;
  8. NSArray *_arr2;
  9. }
  10. @end
  11. @implementation PopViewController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. // Do any additional setup after loading the view.
  15. self.view.backgroundColor = [UIColor whiteColor];
  16. _arr1 = @[@"扫一扫",@"加好友",@"创建讨论组",@"发送到电脑",@"面对面快传",@"收钱"];
  17. _arr2 = @[@"right_menu_QR",@"right_menu_addFri",@"right_menu_multichat",@"right_menu_sendFile",@"right_menu_facetoface",@"right_menu_payMoney"];
  18. _tableVIew = [[UITableView alloc] initWithFrame:self.view.bounds];
  19. _tableVIew.delegate = self;
  20. _tableVIew.dataSource = self;
  21. _tableVIew.scrollEnabled = YES;
  22. _tableVIew.backgroundColor = [UIColor whiteColor];
  23. [self.view addSubview:_tableVIew];
  24. }
  25. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  26. return _arr2.count;
  27. }
  28. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  29. static NSString *str = @"cellID";
  30. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
  31. if (!cell) {
  32. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
  33. }
  34. cell.textLabel.text = _arr1[indexPath.row];
  35. cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",_arr2[indexPath.row]]];
  36. return cell;
  37. }
  38. //重置本控制器的大小
  39. -(CGSize)preferredContentSize{
  40. if (self.popoverPresentationController != nil) {
  41. CGSize tempSize ;
  42. tempSize.height = self.view.frame.size.height;
  43. tempSize.width = 155;
  44. CGSize size = [_tableVIew sizeThatFits:tempSize]; //返回一个完美适应tableView的大小的 size
  45. return size;
  46. }else{
  47. return [super preferredContentSize];
  48. }
  49. }
  50. - (void)didReceiveMemoryWarning {
  51. [super didReceiveMemoryWarning];
  52. // Dispose of any resources that can be recreated.
  53. }
  54. /*
  55. #pragma mark - Navigation
  56. // In a storyboard-based application, you will often want to do a little preparation before navigation
  57. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  58. // Get the new view controller using [segue destinationViewController].
  59. // Pass the selected object to the new view controller.
  60. }
  61. */
  62. @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. 使用angular的HttpClient搭配rxjs

    一.原Http使用总结 使用方法 在根模块或核心模块引入HttpModule 即在AppModule或CoreModule中引入HttpModule: import { HttpModule } fr ...

  2. kettle使用正则表达式动态获取excel表

  3. 单表ORM框架

    基本描述 1.首先是一个单表的ORM框架,多表连接查询请使用视图或者使用SqlHelper查询,然后转换成实体集合. 2.目前仅完成基本结构和MySQL部分. 3.目前欠缺Lambda表达式解析,所以 ...

  4. sed修炼系列(四):sed中的疑难杂症

    本文目录:1 sed中使用变量和变量替换的问题2 反向引用失效问题3 "-i"选项的文件保存问题4 贪婪匹配问题5 sed命令"a"和"N" ...

  5. JQuery的动态加载class无法实现点击时间的解决方案

    //对于 加载过来class 的del_a 实现点击事情 $(document).on('click',".del_a",function(){ $(".mark_id& ...

  6. 再起航,我的学习笔记之JavaScript设计模式20(策略模式)

    策略模式 策略模式(Strategy):将定义的一组算法封装起来,使其相互之间可以替换.封装的算法具有一定的独立性,不会随客户端变化而变化. 其实策略模式在我们生活中可应用的地方还是比较多的,比如在商 ...

  7. Linux-grep 命令和find 命令 (6)

    grep与find区别: grep:查找指定目录下过滤文本文件中行数据 find:查找指定目录下文件 grep使用 格式:   grep "text"   *  [选项] 选项: ...

  8. 附录:MySQL忘记root密码

    中小型规模网站集群架构:MySQL忘记root密码 : 矮哥linux运维群:93324526 前言 你忘记系统root密码的时候,你怎么解决的? 不就是single用户进行修改密码吗?这里原理是类似 ...

  9. 团队作业4——第一次项目冲刺 SeCOnd DaY

    项目冲刺--Double Kill 喂喂喂,你好你好,听得见吗?这里是天霸动霸.tua广播站,我是主播小学生¥-¥ 第一次敏捷冲刺平稳的度过了第一天,第一天的任务大家也圆满完成啦[拍手庆祝],那么今天 ...

  10. 201521123074 《Java程序设计》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰,内容覆盖 ...