Skip to content
Discussion options

You must be logged in to vote

PAG 本身不支持在 AE 中添加点击事件,但提供了运行时获取点击位置对应图层的 API,可以在代码中实现交互逻辑。

实现思路

  1. 点击效果做成原子 PAG 文件:在 AE 中单独制作点击效果动画(透明度变化、缩放等),导出为独立的 PAG 文件
  2. 使用 getLayersUnderPoint 获取点击位置的图层
  3. 点击时动态添加效果:通过 PAGComposition 的 addLayer 将点击效果 PAG 动态添加到对应位置播放

示例代码(iOS):

// 监听点击事件
@objc func handleTap(_ gesture: UITapGestureRecognizer) {
    let point = gesture.location(in: pagView)
    
    // 获取点击位置的图层
    let layers = pagView.getLayersUnderPoint(point)
    
    for layer in layers {
        if layer.layerName == "button" {
            // 加载点击效果 PAG 文件
            let clickEffect = PAGFile.load("click_effect.pag")
            // 设置位置
            clickEffect.setMatrix(layer.matrix())
            // 动态添加到 composition
            …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kevingpqi123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants