当前位置: 首页 > news >正文

AMPopTip - 优雅的iOS动画提示框库

AMPopTip

AMPopTip 是一个优雅的动画弹出提示框,可以从指定框架弹出。您可以指定弹出方向以及指向其原点的箭头。颜色、边框半径和字体都可以轻松自定义。此弹出提示框可用于为您的 UI 提供微妙的提示,并提供有趣的引导弹窗。

功能特性

  • 多种弹出方向:支持上、下、左、右及无箭头居中显示
  • 高度可定制:轻松自定义颜色、边框半径、字体等外观属性
  • 流畅动画:提供平滑的显示和隐藏动画效果
  • 简单易用的API:几行代码即可实现复杂的提示效果
  • 自动布局适应:智能适应不同屏幕尺寸和方向
  • Swift编写:基于 Swift 的现代化实现,性能优异

安装指南

CocoaPods

Podfile 中添加:

pod 'AMPopTip'

然后运行:

pod install
open App.xcworkspace

Carthage

Cartfile 中添加:

github "andreamazz/AMPopTip"

然后运行:

carthage update

AMPopTip.framework 添加到项目中,并在代码中导入:

import AMPopTip

使用说明

基本用法

显示弹出提示非常简单:

let popTip = PopTip()
popTip.show(text: "嘿!看这里!", direction: .up, maxWidth: 200, in: view, from: someView.frame)

无箭头居中显示

popTip.show(text: "嘿!看这里!", direction: .none, maxWidth: 200, in: view, from: view.frame)

自定义外观

let popTip = PopTip()
popTip.bubbleColor = UIColor.blue
popTip.textColor = UIColor.white
popTip.cornerRadius = 10
popTip.font = UIFont.systemFont(ofSize: 14)
popTip.show(text: "自定义样式提示", direction: .down, maxWidth: 200, in: view, from: button.frame)

核心代码

以下是 AMPopTip 的核心实现代码:

// 主要显示方法
public func show(text: String, direction: PopTipDirection, maxWidth: CGFloat, in view: UIView, from frame: CGRect) {self.text = textself.direction = directionself.containerView = viewself.from = frame// 配置外观configureBubble()configureText()// 计算位置calculatePosition()// 添加动画addShowAnimation()
}
// 气泡配置
private func configureBubble() {bubbleView.backgroundColor = bubbleColorbubbleView.layer.cornerRadius = cornerRadiusbubbleView.layer.shadowColor = UIColor.black.cgColorbubbleView.layer.shadowOffset = CGSize(width: 0, height: 2)bubbleView.layer.shadowRadius = 3bubbleView.layer.shadowOpacity = 0.1
}
// 箭头绘制
private func drawArrow() {let arrowPath = UIBezierPath()switch direction {case .up:arrowPath.move(to: CGPoint(x: arrowPosition.x, y: arrowPosition.y))arrowPath.addLine(to: CGPoint(x: arrowPosition.x - arrowSize, y: arrowPosition.y + arrowSize))arrowPath.addLine(to: CGPoint(x: arrowPosition.x + arrowSize, y: arrowPosition.y + arrowSize))case .down:arrowPath.move(to: CGPoint(x: arrowPosition.x, y: arrowPosition.y))arrowPath.addLine(to: CGPoint(x: arrowPosition.x - arrowSize, y: arrowPosition.y - arrowSize))arrowPath.addLine(to: CGPoint(x: arrowPosition.x + arrowSize, y: arrowPosition.y - arrowSize))// 其他方向...}arrowPath.close()bubbleColor.setFill()arrowPath.fill()
}
// 显示动画
private func addShowAnimation() {transform = CGAffineTransform(scaleX: 0.1, y: 0.1)alpha = 0UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.8, options: .curveEaseOut, animations: {self.transform = .identityself.alpha = 1})
}

AMPopTip 提供了完整的提示框解决方案,通过简洁的 API 和丰富的自定义选项,让开发者能够轻松创建专业的用户引导和界面提示效果。
更多精彩内容 请关注我的个人公众号 公众号(办公AI智能小助手)
对网络安全、黑客技术感兴趣的朋友可以关注我的安全公众号(网络安全技术点滴分享)

公众号二维码

公众号二维码

http://www.hskmm.com/?act=detail&tid=30417

相关文章:

  • 2026年深度对比值得推荐的10个在线客服系统
  • 文件名中有空格比较烦人
  • 20232421 2024-2025-1 《网络与系统攻防技术》实验一实验报告
  • 十月总结
  • 20251013 之所思 - 人生如梦
  • Markdown 基本语法
  • 简单工单系统的实现-客服系统中增加创建工单功能
  • 日总结 10
  • # 20232421 2024-2025-1 《网络与系统攻防技术》实验一实验报告
  • 20232317 2025-2026-1《网络与系统攻防技术》实验一实验报告
  • 给一个字符串数组,输出不同的部分
  • 连接 USB 设备
  • SpringBoot-day1(快速上手SpringBoot,SpringBoot简介,SpringBoot基础配置,属性配置,yaml文件) - a
  • Chroma私有化:本地部署完整方案
  • 嵌入式-C++面经2
  • PHP转Go系列 | 如何将 PHP 项目快速迁移到 Go 上?
  • 详细介绍:【OpenHarmony】用户文件服务模块架构
  • 详细介绍:全新 CloudPilot AI:嵌入 Kubernetes 的 SRE Agent,降本与韧性双提升!
  • “环境变量”是什么, 为什么要配置环境变量 --初学者
  • AI元人文:对大模型的召唤——未来哪吒
  • https与http区别思维拓扑图 - krt
  • Java 装饰器模式(Decorator) - krt
  • Python INI 文件读写利器 configparser
  • tcp/ip五层协议模型--思维拓扑图 - krt
  • springboot模式与应用案例--思维拓扑图 - krt
  • DAY04
  • AlexNet vs LeNet 对比实验
  • QT:获取文件信息之创建日期方法created()方法--废弃
  • 排列组合 容斥 总结
  • 10.13每日总结