//
//  WA_PreView.swift
//  wallpaper_project
//
//  Created by 忆海16 on 2024/3/12.
//

import UIKit


class WA_PreView: UIView {
    @IBOutlet weak var flashView: UIView!
    
    @IBOutlet weak var cameraV: UIView!
    
    var touchBlock:(()->())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        commonInit()

    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    
    }
    
    private func commonInit() {
          guard let view = loadViewFromNib() else { return }
          view.frame = bounds
          addSubview(view)
          seeUI()
      }
    private func loadViewFromNib() -> UIView? {
          let nib = UINib(nibName: "WA_PreView", bundle: nil)
          return nib.instantiate(withOwner: self, options: nil).first as? UIView
      }
    

    private func seeUI() {
        self.flashView.layer.cornerRadius = 25
        self.flashView.clipsToBounds = true
         
        self.cameraV.layer.cornerRadius = 25
        self.cameraV.clipsToBounds = true
         
     }
    
 

    @IBAction func hidView(_ sender: UIButton) {
        UIView.animate(withDuration: 1.0, animations: {
            self.frame.origin.x = -self.frame.width
        }) { (finished) in
            // 移除自定义视图
            self.removeFromSuperview()
        }
        
        if self.touchBlock != nil{
            self.touchBlock!()
            
        }
    }

    
}
