2017-03-27 4 views
1

Xcode 놀이터에서 작동하도록 SAConfettiView 프레임 워크를 만들려고합니다. 하지만 위의 코드를 사용하면 색종이 애니메이션이 표시되지 않습니다.Xcode 놀이터에서 SAConfettiView를 실행할 수 없습니다.

import UIKit 
import PlaygroundSupport 

var view = UIView(frame: UIScreen.main.bounds) 
var confettiView: SAConfettiView! 
confettiView = SAConfettiView(frame: view.bounds) 
confettiView.type = .Star 
view.addSubview(confettiView) 
confettiView.startConfetti() 
view.backgroundColor = .red 
PlaygroundPage.current.liveView = view 
PlaygroundPage.current.needsIndefiniteExecution = true 

내가 뭘 잘못하고 있니? Sources 폴더에 ConfettiView.swift 제대로 이미지를로드하지 않기 때문에

Download playground here

답변

2

이입니다.

이 하나 자신의 image(for type: ConfettiType) -> UIImage? 방법을 바꾸기 : 나는 Bundle.main.url를 사용

func image(for 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 
    } 

    guard let url = Bundle.main.url(forResource: fileName, withExtension: "png"), 
     let data = try? Data(contentsOf: url) else 
    { 
     return nil 
    } 

    return UIImage(data: data) 
} 

제대로 색종이 이미지를로드 할 수 있습니다.

enter image description here