Swift Playground XCPShowView “Unable to satisfy co

2019-07-02 04:47发布

问题:

I'm trying to get a Live View to show a simple animation in a Swift Playground. Whenever I import the XCPlayground framework to execute the XCPShowView function i get this error:

Playground execution failed: error: Couldn't lookup symbols:_CGPointMake

The error changes for a few other "symbols" as well, including CGRectMake.
After being advised to modifying my code to remove the "make" from methods such as CGRectMake I still get an error from Xcode when I try to animate my view. The error message is really long, but basically it says

"Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want."

Here is the code I am trying to work with:

//Circle Button
class timerButtonGraphics: UIView {
    override func drawRect(rect: CGRect) {
        let colorGreen = UIColor(red: 0.310, green: 0.725, blue: 0.624, alpha: 1.000)
        let colorRed = UIColor(red: 241/255, green: 93/255, blue: 79/255, alpha: 100)
        var bounds = self.bounds
        var center = CGPoint()
        center.x = bounds.origin.x + bounds.size.width / 2
        center.y = bounds.origin.y + bounds.size.height / 2
        var radius = 61
        var path:UIBezierPath = UIBezierPath()
        path.addArcWithCenter(center, radius: CGFloat(radius), startAngle: CGFloat(0.0), endAngle: CGFloat(Float(M_PI) * 2.0), clockwise: true)
        path.strokeWithBlendMode(kCGBlendModeNormal, alpha: 100)
        path.lineWidth = 2
        if strokeRed == true {
            colorRed.setStroke()
        }
        else {
            colorGreen.setStroke()
        }
        path.stroke()
    }
    var strokeRed = true
    }

var test = timerButtonGraphics(frame: CGRect(x: 0, y: 400, width: 400, height: 400))

UIView.animateWithDuration(2.0, delay: 2, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5, options: nil, animations: {
    test.transform = CGAffineTransformMakeTranslation(0.5, 0)
    }, completion: nil)

XCPShowView("Circle Animation", test)

回答1:

try with this, maybe it can help you

test.setTranslatesAutoresizingMaskIntoConstraints(false)