2017-12-20 16 views
0

그래서 저는 높은 점수에 도달했을 때 실행되는 UIView이라는 색종이 하위 클래스를 생성합니다. 그러나 색종이가 실행되면 내 단추가 끊어 질 수 없으므로 문제가됩니다. 색종이가 실행되지 않으면 내 버튼을 클릭 할 수 있으며 오류가 없습니다. 제발 도와주세요, 몇 시간 동안이 문제를 해결하려고 노력했습니다.Swift - UIView 추가 후 클릭 할 수없는 버튼

override func viewDidLoad() { 
    super.viewDidLoad() 
    if UserDefaults.standard.integer(forKey: "Score") > UserDefaults.standard.integer(forKey: "Highscore") { 
confettiView.startConfetti() 
     delay(3, completion: { 
      confettiView.stopConfetti() 
     }) 
} 

가 여기에 색종이가 만들어 내 코드입니다 :

여기에 색종이가 실행되는 내 코드입니다

import UIKit 
import QuartzCore 

public class SAConfettiView: UIView { 

    public enum ConfettiType { 
     case Confetti 
     case Triangle 
     case Star 
     case Diamond 
     case Image(UIImage) 
    } 

    var emitter: CAEmitterLayer! 
    public var colors: [UIColor]! 
    public var intensity: Float! 
    public var type: ConfettiType! 
    private var active :Bool! 

    required public init?(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 
     setup() 
    } 

    public override init(frame: CGRect) { 
     super.init(frame: frame) 
     setup() 
    } 

    func setup() { 
     colors = [UIColor(red:0.95, green:0.40, blue:0.27, alpha:1.0), 
     UIColor(red:1.00, green:0.78, blue:0.36, alpha:1.0), 
     UIColor(red:0.48, green:0.78, blue:0.64, alpha:1.0), 
     UIColor(red:0.30, green:0.76, blue:0.85, alpha:1.0), 
     UIColor(red:0.58, green:0.39, blue:0.55, alpha:1.0)] 
     intensity = 0.5 
     type = .Confetti 
     active = false 
    } 

    public func startConfetti() { 
     emitter = CAEmitterLayer() 
     emitter.emitterPosition = CGPoint(x: frame.size.width/2.0, y: 0) 
     emitter.emitterShape = kCAEmitterLayerLine 
     emitter.emitterSize = CGSize(width: frame.size.width, height: 1) 

     var cells = [CAEmitterCell]() 
     for color in colors { 
      cells.append(confettiWithColor(color: color)) 
     } 

     emitter.emitterCells = cells 
     layer.addSublayer(emitter) 
     active = true 
    } 

    public func stopConfetti() { 
     emitter?.birthRate = 0 
     active = false 
    } 

    func imageForType(type: ConfettiType) -> UIImage? { 

     var fileName: String! 

     switch type { 
      case .Confetti: 
      fileName = "confetti" 
      case .Triangle: 
      fileName = "triangle" 
      case .Star: 
      fileName = "star" 
      case .Diamond: 
      fileName = "diamond" 
      case let .Image(customImage): 
      return customImage 
     } 
     /* 
     let path = Bundle(for: SAConfettiView.self).path(forResource: "SAConfettiView", ofType: "bundle") 
     let bundle = Bundle(path: path!) 
     let imagePath = bundle?.path(forResource: fileName, ofType: "png") 
     let url = NSURL(fileURLWithPath: imagePath!) 
     let data = NSData(contentsOf: url as URL) 
     if let data = data { 
      return UIImage(data: data as Data)! 
     } 
     return nil */ 
     return UIImage(named: fileName) 
    } 

    func confettiWithColor(color: UIColor) -> CAEmitterCell { 
     let confetti = CAEmitterCell() 
     confetti.birthRate = 6.0 * intensity 
     confetti.lifetime = 14.0 * intensity 
     confetti.lifetimeRange = 0 
     confetti.color = color.cgColor 
     confetti.velocity = CGFloat(350.0 * intensity) 
     confetti.velocityRange = CGFloat(80.0 * intensity) 
     confetti.emissionLongitude = CGFloat(M_PI) 
     confetti.emissionRange = CGFloat(M_PI_4) 
     confetti.spin = CGFloat(3.5 * intensity) 
     confetti.spinRange = CGFloat(4.0 * intensity) 
     confetti.scaleRange = CGFloat(intensity) 
     confetti.scaleSpeed = CGFloat(-0.1 * intensity) 
     confetti.contents = imageForType(type: type)!.cgImage 
     return confetti 
    } 

    public func isActive() -> Bool { 
     return self.active 
    } 
} 
+0

'confettiView'개체를 어떻게 만들고 슈퍼 뷰에 추가했는지 보여줄 수 있습니까? –

답변

0

색종이를 실행 한 후에 버튼 하위보기를 앞으로 가져 오십시오.

희망이 도움이됩니다.

0

그것은 당신의 새로운보기 아래에있는 버튼보기를 가리는 것 같다. 모든 것이 끝나면 stopConfetti() 메소드 내의 슈퍼 뷰에서 색종이 뷰를 제거하는 것이 가장 이상적입니다.