我们先来看一下效果吧:

分析:这个带箭头的弹框其实是一个控制器,通过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带箭头弹框的更多相关文章

  1. div+css实现圆形div以及带箭头提示框效果

    .img{ width:90px; height:90px; border-radius:45px; margin:0 40%; border:solid rgb(100,100,100) 1px;& ...

  2. div+css制作带箭头提示框效果图(原创文章)

    一直都在看站友们的作品,今天也来给大家分享一个小的效果,第一次发还有点小紧张呢,语言表达能力不是很好,还请见谅…^ 先来个简单点的吧,上效果图 刚开始在网上看到效果图的时候感觉好神奇,当我试着写出来的 ...

  3. 使用Bootstrap Popover实现一个弹框上三角形的代码记录

          $(function () {        var options = {          trigger: 'manual',          content: function ...

  4. 圆角带箭头的提示框css实现

    css是一个很强大的东西,很多网页效果,我们可以通过css直接实现.今天给大家分享的是一个用css实现的圆角带箭头的提示框. 效果如下图: 这一个样式主要涉及到了css的边框样式border的运用和定 ...

  5. iOS 带箭头菜单选项弹窗LFPopupMenu

    一.效果图 由于是模拟器缩得比较小,一些细线可能显示不出来,不是bug哈. 二.用法 LFPopupMenuItem *item1 = [LFPopupMenuItem createWithTitle ...

  6. 考拉Android统一弹框

    作者:钱成杰 背景 在快速开发的背景下,经历了n个版本后的考拉Android App中已经存在了各种各样看似相同却各有差别的弹框样式.其中包括系统弹框和自定义弹框,并且在线上时常会出现IllegalA ...

  7. 参考bootstrap中的popover.js的css画消息弹框

    前段时间小颖的大学同学给小颖发了一张截图,图片类似下面这张图: 小颖当时大概的给她说了下,其实小颖也不知道上面那个三角形怎么画嘻嘻,给她说了DOM结构,具体的css让她自己百度,今天小颖自己参考boo ...

  8. 使用纯CSS实现带箭头的提示框

    爱编程爱分享,原创文章,转载请注明出处,谢谢!http://www.cnblogs.com/fozero/p/6187323.html 1.全部代码 <!DOCTYPE html> < ...

  9. iOS 新浪微博-2.0 搜索框/标题带箭头/下拉菜单

    不管是搜索框还是下拉菜单,我们都需要对背景的图片进行拉伸.定义一个Category分类对图片进行操作. UIImage+Effect.h #import <UIKit/UIKit.h> @ ...

随机推荐

  1. Windows Azure HandBook (5) Azure混合云解决方案

    <Windows Azure Platform 系列文章目录> 在很多情况下,我们都会遇到本地私有云和公有云做互通互联的混合云场景.对于这种混合云的场景,微软的Windows Azure会 ...

  2. 【Swift学习】Swift编程之旅(四)基本运算符

    Swift支持大部分标准C语言的运算符, 且改进许多特性来减少常规编码错误.如赋值符 = 不返回值, 以防止错把等号 == 写成赋值号 = 而导致Bug. 数值运算符( + , -, *, /, %等 ...

  3. 五、BLE(下)

    1.1       GATT server Service 通过走读代码, GATT Server作为一个GATT service,我是没有发现其发挥了多大功能,其负责处理的消息GATT_SERVER ...

  4. C#中的枚举类型enum用法

    定义一个简单的枚举类型:   enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};        //这时候         Days.Sat = 0 ,后面依 ...

  5. 孙鑫MFC学习笔记11:保存图像

    1.CPtrArray指针数组 2.CPtrArray返回void指针,需要做类型转换 3.View类中的OnPaint调用OnPrepareDC和OnDraw,如果覆盖OnPaint,就不会调用On ...

  6. 基于TCP和多线程实现无线鼠标键盘-GestureDetector

    为了实现无线鼠标,需要识别出用户在手机屏幕上的滑动动作,这就需要用到GestureDetector类. 首先是activity_main.xml: <LinearLayout xmlns:and ...

  7. 【Java每日一题】20161128

    package Nov2016; import java.util.ArrayList; import java.util.List; public class Ques1128 { public s ...

  8. 【转】持久化消息队列之MEMCACHEQ

    G MEMCACHEQ AS MESSAGE QUEUE PHP,消息队列,MEMCACHEQ 使用消息队列(MESSAGE QUEUE)可以把某些耗时的工作推后,然后在后台慢慢地去执行,这样就不会让 ...

  9. Linux System Calls Hooking Method Summary

    http://www.cnblogs.com/LittleHann/p/3854977.html http://www.cnblogs.com/cozy/articles/3175615.html h ...

  10. 从零开始学Python04作业源码:模拟ATM电子银行(仅供参考)

    bin目录:程序启动入口 ATM_start.py: #!/usr/bin/python # -*- coding: utf-8 -*- # 模拟ATM电子银行+登录账户权限控制+管理员管理模块 # ...