彈窗提示:
照片或視頻不可用
此APP正在不受支持的配置下使用“照片”選擇器
英文為:
Photo or Video Unavailable
This app is using the Photos picker in an unsupported configuration.
經(jīng)過翻官方文檔荒辕,在這里找到了答案:
https://developer.apple.com/documentation/photokit/phpickerviewcontroller
(進入頁面直接搜“17”定位)
大致意思是你讓PHPickerViewController的view由于各種原因“不可見”了镰吆。這種不可見并非我們通俗理解的不可見。蘋果文檔中舉例說明了缚去,比如給view設(shè)置了非100%的不透明度路克,或者其他東西蓋住它了樟结,它就會忽略觸摸交互李皇。
看了下app牢硅,我是給全局加了水印View,為了能保證水印View能永遠在所有頁面的最上層搞动,將其zPosition為Float最大值)
watermarkView.layer.zPosition = .greatestFiniteMagnitude
所以在相冊彈出后灰羽,水印View在相冊View之上驮履,即使水印為全透明且透傳所有的點擊事件,但在iOS17上蘋果仍舊給攔截住了廉嚼。
最終我的解決方案是把水印View從繼承UIView
改為繼承UIWindow
class WatermarkView: UIWindow {
static var wmView: WatermarkView?
public static func showIfNeeded(_ view: UIView? = nil, waterMarkString: String?) {
guard waterMarkString.count > 0 else { return }
guard case let window?? = UIApplication.shared.delegate?.window else { return }
wmView?.isHidden = true
let waterView = CLSWatermarkView()
waterView.frame = UIScreen.main.bounds
waterView.backgroundColor = .clear
waterView.rootViewController = UIViewController()
waterView.windowLevel = .statusBar
waterView.isHidden = false
var x: CGFloat = 0
var y: CGFloat = 0
var lineCount: Int = 0
while (true) {
let label = UILabel()
label.text = waterMarkString
label.textColor = UIColor.black
label.alpha = 0.1
label.font = UIFont.systemFont(ofSize: 14)
waterView.addSubview(label)
label.sizeToFit()
label.frame = CGRect(x: x, y: y, width: label.width, height: label.height)
label.transform = CGAffineTransform(rotationAngle: Double.pi / -12)
x += label.width + 100
if x > UIScreen.main.bounds.width && y > UIScreen.main.bounds.height {
break
}
if x > UIScreen.main.bounds.width {
y += 70
lineCount += 1
if lineCount % 2 == 0 {
x = 0
} else {
x = 104
}
}
}
wmView = waterView
}
public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
return nil
}
}