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

iOS 16中CIMotionBlur模糊效果异常问题咨询

iOS 16下SKEffectNode搭配CIMotionBlur异常问题修复

问题复现

以下代码在iOS 16及后续版本中,CIMotionBlur模糊效果出现偏移、拉伸的异常表现,但在iOS 16之前版本运行正常。

测试代码

class GameScene: SKScene {
    override func didMove(to view: SKView) {
        
        let shapeNode = SKShapeNode(circleOfRadius: 30)
        shapeNode.fillColor = .green
        shapeNode.strokeColor = .clear
        addChild(shapeNode)

        let blurredShapeNode = SKShapeNode(circleOfRadius: 30)
        blurredShapeNode.fillColor = .red
        blurredShapeNode.strokeColor = .clear
    
        let effectNode = SKEffectNode()
        addChild(effectNode)
        effectNode.addChild(blurredShapeNode)
    
        let blurAngle = NSNumber(value: 0)
        effectNode.filter = CIFilter(
        name: "CIMotionBlur", parameters: [kCIInputRadiusKey: 30, kCIInputAngleKey: blurAngle])
    }
}

效果对比

  • iOS 15.5(正常效果):
    iOS 15.5正常模糊效果

  • iOS 16(异常效果):
    iOS 16模糊偏移拉伸

解决方案

iOS 16中SKEffectNode的滤镜渲染逻辑或坐标系规则发生了变化,可通过以下两种方式修复:

方法1:开启光栅化(推荐)

给effectNode开启光栅化,强制提前渲染子节点内容后再应用滤镜,直接规避坐标系偏移问题:

// 在添加子节点后添加该行代码
effectNode.shouldRasterize = true

方法2:手动指定滤镜输入范围

通过给CIMotionBlur滤镜设置输入范围参数,匹配节点的实际渲染区域,修正偏移:

// 替换原滤镜初始化代码
let blurFilter = CIFilter(name: "CIMotionBlur", parameters: [
    kCIInputRadiusKey: 30,
    kCIInputAngleKey: blurAngle
])!
// 传入节点的实际帧范围
blurFilter.setValue(
    CIVector(
        x: blurredShapeNode.frame.minX,
        y: blurredShapeNode.frame.minY,
        z: blurredShapeNode.frame.width,
        w: blurredShapeNode.frame.height
    ),
    forKey: kCIInputExtentKey
)
effectNode.filter = blurFilter

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 22:10:26