✨UIPopoverController 在iOS9之后被废弃了,,,
iOS8 新控件UIPopoverPresentationController可运用在iphone和iPad上,使用基本同 UIPopoverController
  • - (void)iPadAndIphonePopOver {
        MenuViewController *menuVC = [[MenuViewController alloc] init];
        menuVC.modalPresentationStyle = UIModalPresentationPopover;
        menuVC.popoverPresentationController.sourceView = self.view;
        menuVC.popoverPresentationController.sourceRect = self.testButton.frame;
        menuVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
        [self presentViewController:menuVC animated:YES completion:nil];
    }
  
 
code2:
* - (IBAction)popOver:(id)sender {
AddressViewController *contentVC = [[AddressViewController alloc] init];
contentVC.modalPresentationStyle = UIModalPresentationPopover;
contentVC.popoverPresentationController.sourceView = self.view;
contentVC.popoverPresentationController.sourceRect = CGRectMake(, , , );
contentVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
[self presentViewController:contentVC animated:YES completion:nil];
}
* AddressViewController.m
* #import "AddressViewController.h" @interface AddressViewController () <UITableViewDelegate, UITableViewDataSource> @property (weak, nonatomic) IBOutlet UITableView *masterTableView; // 省份tableView
@property (weak, nonatomic) IBOutlet UITableView *detailTableView; // 地区tableView @property (nonatomic, strong) NSArray *masterDataSource; // 省份数据源
@property (nonatomic, strong) NSArray *detailDataSource; // 地区数据源
@property (nonatomic, assign) int masterIndex; // 选中的省份 @end @implementation AddressViewController - (void)viewDidLoad {
[super viewDidLoad]; _masterIndex = ;
self.preferredContentSize = CGSizeMake(, );
} - (NSArray *)masterDataSource {
if (_masterDataSource == nil) {
_masterDataSource = @[@"河南", @"河北", @"江苏", @"浙江", @"广东"];
}
return _masterDataSource;
} - (NSArray *)detailDataSource {
if (_detailDataSource == nil) {
_detailDataSource = @[@[@"郑州", @"洛阳", @"周口", @"开封"],
@[@"石家庄", @"石家庄2"],
@[@"南京", @"苏州", @"淮安", @"淮北", @"句容"],
@[@"杭州", @"温州", @"台州", @"宁波", @"瑞安", @"苍南"],
@[@"广州", @"深圳"]
];
}
return _detailDataSource;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == self.masterTableView) {
return self.masterDataSource.count;
} if (tableView == self.detailTableView) {
return [self.detailDataSource[_masterIndex] count];
}
return ;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.masterTableView) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"master"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"master"];
}
cell.textLabel.text = self.masterDataSource[indexPath.row];
return cell;
} UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"detail"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"detail"];
}
cell.textLabel.text = self.detailDataSource[_masterIndex][indexPath.row];
return cell;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == _masterTableView) {
_masterIndex = (int)indexPath.row;
self.preferredContentSize = CGSizeMake(, );
[_detailTableView reloadData];
} if (tableView == _detailTableView) {
self.preferredContentSize = CGSizeMake(, );
[_detailTableView reloadData];
}
} @end

  

    

 
注意:如果要去掉箭头 permittedArrowDirections = 0;  并且要在设置了 sourceView, sourceRect 之后才会生效
 

 ✨以上都是在iPad上面使用,但是如果在iPhone上使用的话默认就会占满全屏幕,
解决办法是遵循UIPopoverPresentationControllerDelegate 实现adaptivePresentationStyleForPresentationController:代理方法覆盖默认的自适应行为
  • - (void)iPadAndIphonePopOver {
        MenuViewController *menuVC = [[MenuViewController alloc] init];
        menuVC.modalPresentationStyle = UIModalPresentationPopover;
        menuVC.popoverPresentationController.sourceView = self.view;
        menuVC.popoverPresentationController.sourceRect = self.test22.frame;
        menuVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
        menuVC.popoverPresentationController.delegate = self;
        [self presentViewController:menuVC animated:YES completion:nil];
    }
 
  • - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
        return UIModalPresentationNone;
    }
  • // 是否可以dismiss,返回YES代表可以,返回NO代表不可以
    - (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController {
        return NO;
    }
   ✨另外值得注意的一点是,preferredContentSize 应该在 presentedViewController 中实现,也可以重写preferredContentSize 的set get 方法来根据不同的新情况返回不同的尺寸
 
 

iPad 控件 UIPopoverPresentationController 使用 iPhone可用的更多相关文章

  1. iPad 控件UIPopoverController使用

    UIPopoverController 是iPad特有控件,(iOS7-9),在iOS9之后别废弃 使用步骤 设置内容控制器 UIPopoverController直接继承NSObject,不具备可视 ...

  2. js控件设置只读属性和不可用属性

    介绍js实现只读的几种方法: 设置控件只读的话,我们要先清楚哪些没有readOlny这个属性 我知道的checkbox和RadioButton没有readOlny这个属性,我上一篇已经介绍了如何设置c ...

  3. 银联手机支付控件官方使用指南(ios版)

    目录 版本信息... 2 目录      3 1       概述... 1 2       支付流程介绍... 1 3       测试帐号... 2 4       iOS客户端... 3 4.1 ...

  4. 认识基本的mfc控件

    几乎可以在每个windows程序中都看到按钮.复选框.文本框以及下拉列表等等,这些都是控件.而且很多常用的控件已经内置到操作系统当中了,在Visual C++中,这些常用控件已经简答到能用“拖放”这种 ...

  5. 初识Windows窗体(包括各种控件,属性,方法)

    什么是Wind ows窗体? 顾名思义,win dows窗体就是将一些所必须的信息通过窗体的形式展示给客户看.例如:我们经常玩的QQ登陆界面,微信登陆界面,等等,都是以窗体的形式将信息展示给我们看的. ...

  6. ASP.NETserver控件使用之Reportviewer 报表

    1.       Reportviewer 报表 1.1.       Reportviewer控件 注:本教程附2个事例: l  演练:在本地处理模式下将数据库数据源与 ReportViewer W ...

  7. asp.net textbox控件基础

    asp.net有两种控件,一种是html控件,一种是asp控件,在说textbox控件之前,先看看按钮的两个命令oncommand和onclick.每次点击按钮后,都会提交命令,但是程序会首先执行Pa ...

  8. 百度地图隐藏缩放控件比例尺Logo

    对于百度地图最新版V3.7.3,以前的隐藏控件方法失效,可用以下方法隐藏: 1.隐藏缩放控件: mMapView.showZoomControls(false); 2.隐藏比例尺: mMapView. ...

  9. RichEdit控件 SDK 参考手册

    RichEdit控件 SDK 参考手册 摘要: 本文对Rich Edit控件底层消息机制进行了讲解,以期读者对Windows平台下的Rich Edit控件有一个更深入的认识,同时对于使用Win32 S ...

随机推荐

  1. phpMyAdmin如何设置float小数点

    在长度/值设置 5,2就行了哈

  2. spring加载bean实例化顺序

    问题来源: 有一个bean为 A,一个bean为B.想要A在容器实例化的时候的一个属性name赋值为B的一个方法funB的返回值. 如果只是在A里单纯的写着: private B b;private ...

  3. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(十二) 代码重构使用反射工厂解耦(一)缓存切换

    前言 上一篇中,我们用了反射工厂来解除BLL和UI层耦合的问题.当然那是最简单的解决方法,再复杂一点的程序可能思路相同,但是在编程细节中需要考虑的就更多了,比如今天我在重构过程中遇到的问题.也是接下来 ...

  4. cPage分页详细介绍

    asp.net中各种数据控件,datalist.gridview.Repeater等分页是最常用的功能,几乎任何一个B/S项目,无论是系统还是网站都会用到.分页时,读取整个数据,直接绑定到控件,都可以 ...

  5. Visual Studio并发Qpar优化效果

    IOCP客户端的connect线程FOR循环中添加强制并行,1万/S并发connect+send+recv+close,任务管理器使用从60%降到20%. Visual Studio性能监控CPU使用 ...

  6. Arrays和Collection之间的转换

    1.将数组转换成固定大小的列表: public static <T> List<T> asList(T... a)参数 T... a:数组元素 返回值 List<T> ...

  7. windows使用nginx实现网站负载均衡测试实例

    如果你关注过nginx,必定知道nginx这个软件有什么用的,如果你的网站访问量越来越高,一台服务器已经没有办法承受流量压力,那就增多几台服务器来做负载吧.做网站负载可以买硬件设备来实现,比如F5,不 ...

  8. [Linux] 关于Centos6中ulimit nproc用户进程数的限制

    一.缘由: 在启动mongodb的时候,有Warning提示soft rlimits too low,就是用户使用进程数过小,遂调高系统资源关于用户最大进程数的限制ulimit -u. 先暂时使设置生 ...

  9. GridLookUpEdit多列模糊查询最简单方式 z

    GridLookUpEdit的知识库是RepositoryItemGridLookUpEdit,切确的说GridLookUpEdit只是RepositoryItemGridLookUpEdit的一个壳 ...

  10. android 代码生成selector drawable

    public static StateListDrawable makeSelector(Context context, int idNormal, int idPressed, int idFoc ...