popover带箭头弹框
我们先来看一下效果吧:

分析:这个带箭头的弹框其实是一个控制器,通过Modal方式展现,但跟传统模态方式效果不一样,我们一眼就能看出。
Xib方式实现popover:
1、segue的时候选择Present As Popover

2、我们看下segue的属性:

3、重写prepareforsegue方法:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// 1、判断跳转控制器的类型
if segue.destination.isKind(of: YSSportMapModeVC.self){
// 2、验证popover和传统模态之间的区别
// 只有为popover时,popoverPresentationController有值,否则为nil
// print(segue.destination.popoverPresentationController!)
let vc:YSSportMapModeVC = segue.destination as! YSSportMapModeVC
// 3、设置代理
vc.popoverPresentationController?.delegate = self
// 4、其实我们展现的还是segue.destination,popoverPresentationController只是用来设置展现效果的
// 设置展现的控制器的大小,如果width=0,宽度交给系统设置
vc.preferredContentSize = CGSize(width: , height: )
// 5、设置地图视图的显示模式
vc.didSelectedMapMode = {(mapType:MAMapType) in
self.mapView.mapType = mapType
}
// 6、设置vc的当前显示模式
vc.currentMapType = mapView.mapType
}
}
4、实现代理方法:
// MARK: - UIPopoverPresentationControllerDelegate
extension YSSportMapVC:UIPopoverPresentationControllerDelegate{
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
// 不让系统自适应
return .none
}
}
代码方式实现popover:
#import "ViewController.h" @interface ViewController () <UIPopoverPresentationControllerDelegate> // 通过xib设置的按钮,传统模态展现
@property (weak, nonatomic) IBOutlet UIButton *demoButton; @end @implementation ViewController /**
1. 添加加号按钮
2. 点击加号按钮以popover的方式`展现`一个视图控制器
*/
- (void)viewDidLoad {
[super viewDidLoad]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
btn.center = self.view.center; [self.view addSubview:btn]; [btn addTarget:self action:@selector(popover:) forControlEvents:UIControlEventTouchUpInside];
} - (void)popover:(UIButton *)sender { UIViewController *vc = [UIViewController new]; vc.view.backgroundColor = [UIColor redColor]; // 1. 在 iPhone 上默认是模态展现,设置展现类型为 popover
vc.modalPresentationStyle = UIModalPresentationPopover; // 设置弹窗视图控制器视图的大小
vc.preferredContentSize = CGSizeMake(, ); // 2. 设置展现的代理
vc.popoverPresentationController.delegate = self; // 3. 指定弹窗的定位控件 - 使用代码开发,必须设置定位控件
vc.popoverPresentationController.sourceView = sender; // 4. 设置箭头方向朝上
vc.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp; // 5. 设置箭头的位置,原点可以参照某一个控件的尺寸设置,宽高通常用于设置附加的偏移量,通常传入0即可
CGSize size = sender.bounds.size;
vc.popoverPresentationController.sourceRect = CGRectMake(size.width * 0.5, size.height, , ); // 6. 设置绕开控件,注意,同一时间,只能允许模态展现一个控制器
vc.popoverPresentationController.passthroughViews = @[_demoButton]; // 展现控制器
[self presentViewController:vc animated:YES completion:nil];
} - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
// 不使用系统默认的展现样式!
return UIModalPresentationNone;
} @end
popover带箭头弹框的更多相关文章
- div+css实现圆形div以及带箭头提示框效果
.img{ width:90px; height:90px; border-radius:45px; margin:0 40%; border:solid rgb(100,100,100) 1px;& ...
- div+css制作带箭头提示框效果图(原创文章)
一直都在看站友们的作品,今天也来给大家分享一个小的效果,第一次发还有点小紧张呢,语言表达能力不是很好,还请见谅…^ 先来个简单点的吧,上效果图 刚开始在网上看到效果图的时候感觉好神奇,当我试着写出来的 ...
- 使用Bootstrap Popover实现一个弹框上三角形的代码记录
$(function () { var options = { trigger: 'manual', content: function ...
- 圆角带箭头的提示框css实现
css是一个很强大的东西,很多网页效果,我们可以通过css直接实现.今天给大家分享的是一个用css实现的圆角带箭头的提示框. 效果如下图: 这一个样式主要涉及到了css的边框样式border的运用和定 ...
- iOS 带箭头菜单选项弹窗LFPopupMenu
一.效果图 由于是模拟器缩得比较小,一些细线可能显示不出来,不是bug哈. 二.用法 LFPopupMenuItem *item1 = [LFPopupMenuItem createWithTitle ...
- 考拉Android统一弹框
作者:钱成杰 背景 在快速开发的背景下,经历了n个版本后的考拉Android App中已经存在了各种各样看似相同却各有差别的弹框样式.其中包括系统弹框和自定义弹框,并且在线上时常会出现IllegalA ...
- 参考bootstrap中的popover.js的css画消息弹框
前段时间小颖的大学同学给小颖发了一张截图,图片类似下面这张图: 小颖当时大概的给她说了下,其实小颖也不知道上面那个三角形怎么画嘻嘻,给她说了DOM结构,具体的css让她自己百度,今天小颖自己参考boo ...
- 使用纯CSS实现带箭头的提示框
爱编程爱分享,原创文章,转载请注明出处,谢谢!http://www.cnblogs.com/fozero/p/6187323.html 1.全部代码 <!DOCTYPE html> < ...
- iOS 新浪微博-2.0 搜索框/标题带箭头/下拉菜单
不管是搜索框还是下拉菜单,我们都需要对背景的图片进行拉伸.定义一个Category分类对图片进行操作. UIImage+Effect.h #import <UIKit/UIKit.h> @ ...
随机推荐
- UMeditor宽度自适应
百度编辑器UMeditor,生成富文本编辑框以后,改变窗口大小会出现横向滚动条,即使你调用接口设置了编辑器的宽度为100%.如: var um = UM.getEditor('<%=txtCon ...
- [Java 基础]运算符和表达式
Java运算符 (1)赋值操作符 赋值操作符(=)表示:取右边的值(即右值),把它复制给左边(即左值). 右值可以是任意的常量.变量或表达式(只要可以生成一个值). 左值必须是一个明确的.已命名的变量 ...
- 加速Web开发的9款知名HTML5框架
与手工编码比起来,HTML5框架在准确性和正确率方面给予了保证.大多数HTML5框架都会有一个组合或者包含一些额外的组件,比如jQuery Scripts.CSS3样式表则以改善多媒体特征的功能性和响 ...
- CSS魔法堂:你真的懂text-align吗?
前言 也许提及text-align你会想起水平居中,但除了这个你对它还有多少了解呢?本篇打算和大家一起来跟text-align来一次负距离的交往,你准备好了吗? text-align属性详解 The ...
- 基于MVC4+EasyUI的Web开发框架经验总结(15)--在MVC项目中使用RDLC报表
RDLC是一个不错的报表,有着比较不错的设计模式和展现效果,在我的Winform开发里面,使用RDLC也是一个比较方便操作,如可以参考文章<DevExpress的XtraReport和微软RDL ...
- .Net 高效开发之不可错过的实用工具(转)
.Net 高效开发之不可错过的实用工具(转) 本文摘自: http://www.cnblogs.com/powertoolsteam/p/5240908.html#3372237 Visual Stu ...
- 背水一战 Windows 10 (10) - 资源: StaticResource, ThemeResource
[源码下载] 背水一战 Windows 10 (10) - 资源: StaticResource, ThemeResource 作者:webabcd 介绍背水一战 Windows 10 之 资源 St ...
- How to DEBUG a trigger or procedure
DEBUGGING STORED PROCEDURES Over the past several weeks, we’ve been working on debugging a stored pr ...
- XE7 提交 App(iOS 8)提示「does not contain the correct beta entitlement」问题修复
XE7 提交 App 后,在「Prerelease」里被提示了: Build 1.0.0 does not contain the correct beta entitlement. For more ...
- Go语言的编程范式
由于比较古怪的语言特性,感觉代码的封装性是一种不同的思路. 包管理的火热程度居然没有nodejs高,这是为什么 package form import ( "encoding/gob&quo ...