You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在iOS中使用NotificationBannerSwift关闭横幅的震动效果?

关闭NotificationBannerSwift的震动效果

NotificationBannerSwift 默认会为横幅展示触发触觉震动反馈,要关闭这个效果,只需将 banner 的 haptic 属性设置为 .none 即可。

修改后的完整代码如下:

let banner = FloatingNotificationBanner(title: messageString, titleFont: UIFont.initFrom(style: .textBody), style: .info, colors: BannerColors())
banner.duration = 2.0
banner.transparency = 0.6
banner.haptic = .none // 新增此行关闭震动效果
banner.show(queuePosition: .back, bannerPosition: .bottom, queue: NotificationBannerQueue(maxBannersOnScreenSimultaneously: 1), edgeInsets: UIEdgeInsets(top: 8, left: 8, bottom: 100, right: 8), cornerRadius: 10, shadowBlurRadius: 15)

补充说明

haptic 属性的类型为 NotificationBannerHaptic,可选值包含:

  • .none:完全禁用触觉反馈
  • .light:轻量震动
  • .medium:中等震动
  • .heavy:重度震动
  • .rigid:刚性震动
  • .soft:柔和震动

默认情况下,不同的横幅样式(如.info/.success/.warning/.danger)会对应预设的震动类型,手动设置为 .none 即可覆盖默认行为,关闭所有震动效果。

内容的提问来源于stack exchange,提问作者Inna_K

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 13:30:55