如何在iPhone上绘制“对话气泡”?

2024-05-08

当您右键单击扩展坞中的某个内容时,我试图获得类似于 Mac OS X 中的“语音气泡”效果。这是我现在所拥有的:

我需要得到下部的“三角形”部分。有什么办法可以画出这样的东西并在它周围加上边框吗?这将是为了iPhone app.

提前致谢!

EDIT: Many thanks to Brad Larson, here's what it looks like now: alt text


实际上,我之前已经画过这个确切的形状(底部有一个指向三角形的圆角矩形)。我使用的Quartz绘图代码如下:

CGRect currentFrame = self.bounds;

CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineWidth(context, strokeWidth);
CGContextSetStrokeColorWithColor(context, [MyPopupLayer popupBorderColor]); 
CGContextSetFillColorWithColor(context, [MyPopupLayer popupBackgroundColor]);

// Draw and fill the bubble
CGContextBeginPath(context);
CGContextMoveToPoint(context, borderRadius + strokeWidth + 0.5f, strokeWidth + HEIGHTOFPOPUPTRIANGLE + 0.5f);
CGContextAddLineToPoint(context, round(currentFrame.size.width / 2.0f - WIDTHOFPOPUPTRIANGLE / 2.0f) + 0.5f, HEIGHTOFPOPUPTRIANGLE + strokeWidth + 0.5f);
CGContextAddLineToPoint(context, round(currentFrame.size.width / 2.0f) + 0.5f, strokeWidth + 0.5f);
CGContextAddLineToPoint(context, round(currentFrame.size.width / 2.0f + WIDTHOFPOPUPTRIANGLE / 2.0f) + 0.5f, HEIGHTOFPOPUPTRIANGLE + strokeWidth + 0.5f);
CGContextAddArcToPoint(context, currentFrame.size.width - strokeWidth - 0.5f, strokeWidth + HEIGHTOFPOPUPTRIANGLE + 0.5f, currentFrame.size.width - strokeWidth - 0.5f, currentFrame.size.height - strokeWidth - 0.5f, borderRadius - strokeWidth);
CGContextAddArcToPoint(context, currentFrame.size.width - strokeWidth - 0.5f, currentFrame.size.height - strokeWidth - 0.5f, round(currentFrame.size.width / 2.0f + WIDTHOFPOPUPTRIANGLE / 2.0f) - strokeWidth + 0.5f, currentFrame.size.height - strokeWidth - 0.5f, borderRadius - strokeWidth);
CGContextAddArcToPoint(context, strokeWidth + 0.5f, currentFrame.size.height - strokeWidth - 0.5f, strokeWidth + 0.5f, HEIGHTOFPOPUPTRIANGLE + strokeWidth + 0.5f, borderRadius - strokeWidth);
CGContextAddArcToPoint(context, strokeWidth + 0.5f, strokeWidth + HEIGHTOFPOPUPTRIANGLE + 0.5f, currentFrame.size.width - strokeWidth - 0.5f, HEIGHTOFPOPUPTRIANGLE + strokeWidth + 0.5f, borderRadius - strokeWidth);
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFillStroke);

// Draw a clipping path for the fill
CGContextBeginPath(context);
CGContextMoveToPoint(context, borderRadius + strokeWidth + 0.5f, round((currentFrame.size.height + HEIGHTOFPOPUPTRIANGLE) * 0.50f) + 0.5f);
CGContextAddArcToPoint(context, currentFrame.size.width - strokeWidth - 0.5f, round((currentFrame.size.height + HEIGHTOFPOPUPTRIANGLE) * 0.50f) + 0.5f, currentFrame.size.width - strokeWidth - 0.5f, currentFrame.size.height - strokeWidth - 0.5f, borderRadius - strokeWidth);
CGContextAddArcToPoint(context, currentFrame.size.width - strokeWidth - 0.5f, currentFrame.size.height - strokeWidth - 0.5f, round(currentFrame.size.width / 2.0f + WIDTHOFPOPUPTRIANGLE / 2.0f) - strokeWidth + 0.5f, currentFrame.size.height - strokeWidth - 0.5f, borderRadius - strokeWidth);
CGContextAddArcToPoint(context, strokeWidth + 0.5f, currentFrame.size.height - strokeWidth - 0.5f, strokeWidth + 0.5f, HEIGHTOFPOPUPTRIANGLE + strokeWidth + 0.5f, borderRadius - strokeWidth);
CGContextAddArcToPoint(context, strokeWidth + 0.5f, round((currentFrame.size.height + HEIGHTOFPOPUPTRIANGLE) * 0.50f) + 0.5f, currentFrame.size.width - strokeWidth - 0.5f, round((currentFrame.size.height + HEIGHTOFPOPUPTRIANGLE) * 0.50f) + 0.5f, borderRadius - strokeWidth);
CGContextClosePath(context);
CGContextClip(context);     

如果您不打算使用渐变或其他比简单颜色更复杂的填充,则可以省略最后的剪切路径。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在iPhone上绘制“对话气泡”? 的相关文章

随机推荐

  • Serilog 滚动日志仅记录在一个文件中

    有没有办法设置 Serilog 以在保持最大文件大小的同时继续登录同一文件 换句话说 如果我将最大文件大小指定为 100MB 则该进程应在 添加新条目之前从文件中删除较早的条目 TL DR 号 这File 或其RollingFile前身 不
  • C 中经过的时间

    include
  • 消除 ffmpeg 和 image-magic 命令中的慢速因素

    这些命令的基本思想是创建一个比较 比较定义了过去的一张 jpeg 和现在的一张 jpeg 组合起来 例如它们将相互滑动并显示前后图像 e g https media evercam io v1 cameras 1lowe scnoe com
  • 解释 scipy.stats.entropy 值

    我正在尝试使用scipy stats 熵来估计库尔巴克 莱布勒 KL 两个分布之间的散度 更具体地说 我想使用 KL 作为衡量标准来确定两个分布的一致性 但是 我无法解释 KL 值 例如 t1 numpy random normal 2 5
  • 鉴于我的代码是开源的并且我在服务器上运行,并且我接受近乎原始的代码,那么对我来说最糟糕的情况是什么?

    我正在研究几个案例 在这些案例中 接受近乎原始的代码会容易得多 所以 如果你不能使用 lambda 你能对表达式做的最糟糕的事情是什么 以及如何做 如果不能使用 import 那么对执行的代码最糟糕的情况是什么 如何使用 不能使用 X 扫描
  • 无法将方法组分配给 asp.net、linq、c# 中的隐式类型局部变量

    public void selectqueryasso CustomerOrderResult cso new CustomerOrderResult var a from as1 in ds orders from as2 in ds o
  • 将日期字符串转换为“MM/DD/YY”格式

    我刚刚看到这个例子 我该如何解决这个问题 Hive 元存储包含一个名为 Problem1 的数据库 其中包含一个名为 customer 的表 customer 表包含 9000 万条客户记录 90 000 000 每条记录都有一个生日字段
  • 在Python中使用Counter()来构建直方图?

    我在另一个问题上看到我可以使用Counter 计算一组字符串中出现的次数 所以如果我有 A B A C A A I get Counter A 3 B 1 C 1 但现在 我如何使用该信息来构建直方图 对于您的数据 最好使用条形图而不是直方
  • 无效的跨线程访问问题

    我有两个 ViewModel 类 PersonViewModel 和 PersonSearchListViewModel PersonViewModel 实现的字段之一是通过 WCF 下载的个人资料图像 本地缓存在独立存储中 PersonS
  • 用于格式化和挂载所有可用实例存储设备的脚本

    Amazon 提供实例存储 http docs amazonwebservices com AWSEC2 latest UserGuide InstanceStorage html对于 EC2 实例 如果您使用自己的 AMI 则不会自动为您
  • WordPress 标头位置重定向

    WordPress 遇到问题 我想将页面重定向到文件夹 php adminpage php 内的特定 php 文件 SESSION变量等于 1 假设会话变量为 1 但浏览器返回 Not Found 有什么办法让它发挥作用吗 更新 已解决 使
  • 如何在gitlab存储库中下载单个文件夹或文件

    我有一个存储库 在此存储库中 有多个文件夹可用 我只需要此存储库中的一个文件夹 我已经尝试遵循命令 但它不起作用 克隆 有没有办法只克隆 git 存储库子目录 https stackoverflow com questions 600079
  • 运行 JAR 时“JCE 无法验证提供者 BC”

    在我的 scala 项目中我使用 org bouncycastle bcprov jdk14 1 51 用于密码学 如果它在 Scala IDE 中测试我的项目 它工作得很好 但是一旦我制作了一个 JAR 并尝试通过以下方式运行它java
  • R 中多类分类的 ROC 曲线

    我有一个包含 6 个类别的数据集 我想绘制多类别分类的 ROC 曲线 Achim Zeileis 给出的第一个答案非常好 R中使用rpart包的ROC曲线 https stackoverflow com questions 30818188
  • 为什么我的 Airflow 任务被“外部设置为失败”?

    我使用的是 Airflow 2 0 0 我的任务在运行几秒钟或几分钟后偶尔会被 外部 终止 任务通常会成功运行 都是通过以下方式启动的手动任务 airflow tasks test 以及计划的 DAG 运行 所以我相信这与我的 DAG 代码
  • 如何提高QNX6下Eclipse IDE的性能

    我们在 VMWare 环境中通过 QNX6 运行 Eclipse 速度非常慢 Eclipse 是这样启动的 usr qnx630 host qnx6 x86 usr qde eclipse eclipse data root workspa
  • 慢速 WPF 文本框

    我正在开发一个简单的串行数据查看器 它将用于观察传输到计算机串行端口之一的数据 我使用 C 和 WPF 编写了一个测试应用程序 它只是将最近读取的行放入文本块中 但是 它会跳过所有其他行 我的理论是 在 WPF 渲染窗口之前 新数据会被放入
  • 在大型数据绑定 ObservableCollection 中添加/删除许多项目,而无需冻结 GUI

    我和我的团队正在开发一个 WPF 应用程序 该应用程序显示多个并发 XamDataChart 控件 由 Infragistics 提供 每个图表都绑定到不同的 ObservableCollection 最多可包含 200 万个点 对于每个图
  • Powershell:如何捕获主机的输出

    我正在使用 powershell 自动执行一些与 TFS 中签出 合并相关的任务 当我打电话时 tf get recurse 我得到一堆关于正在检出的文件的数据滚动 该命令生成的最后一行 假设成功 是告知签到号码的行 我想解析它 以便稍后在
  • 如何在iPhone上绘制“对话气泡”?

    当您右键单击扩展坞中的某个内容时 我试图获得类似于 Mac OS X 中的 语音气泡 效果 这是我现在所拥有的 我需要得到下部的 三角形 部分 有什么办法可以画出这样的东西并在它周围加上边框吗 这将是为了iPhone app 提前致谢 ED