//
//  YHFadeView.swift
//  galaxy
//
//  Created by alexzzw on 2024/11/26.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit

class YHFadeView: UIView {
    private let maskLayer = CAGradientLayer()

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupMask()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupMask()
    }

    private func setupMask() {
        // 使用黑色渐变作为mask
        maskLayer.colors = [
            UIColor.black.cgColor,
            UIColor.clear.cgColor,
        ]
        maskLayer.startPoint = CGPoint(x: 0, y: 0)
        maskLayer.endPoint = CGPoint(x: 0, y: 1)

        // 重要：将渐变层设置为mask
        layer.mask = maskLayer
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        // 确保mask大小与视图相同
        maskLayer.frame = bounds
    }
}
