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

UIActivityViewController在iOS15版本iPad上无法正常运行如何解决?

问题原因

iOS 15 对 UIActivityViewController 的 Popover 弹窗布局逻辑做了调整,iOS 14及更早版本中仅设置sourceView即可正常渲染弹窗,iOS 15之后系统会对Popover的布局参数校验更严格,未明确设置sourceRect时会出现布局计算错误,最终导致分享弹窗内容区域渲染为空白。

解决方法
  • 方案1:补充完整Popover布局参数(保留Popover弹窗样式+箭头)
    修改后代码如下:
let activityController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
  
if let popoverPC = activityController.popoverPresentationController {
    popoverPC.sourceView = centerView
    // 新增:设置弹窗锚点对应sourceView的区域,可根据实际展示需求调整
    popoverPC.sourceRect = centerView.bounds
    // 可选:明确指定箭头允许的方向,避免系统自动计算异常
    popoverPC.permittedArrowDirections = .any
}
self.present(activityController, animated: true, completion: {})
  • 方案2:修改弹窗样式规避Popover布局问题
    不需要Popover带箭头的展示样式时,可直接指定弹窗为页Sheet样式,跳过Popover布局逻辑:
let activityController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
// 强制使用页Sheet样式,iPad下也不会走Popover布局逻辑
activityController.modalPresentationStyle = .pageSheet
self.present(activityController, animated: true, completion: {})

补充说明:修改代码前请先确认activityItems数组不为空,且数组内的内容类型符合系统分享组件支持的格式,排除内容本身异常导致的空白问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 08:27:00