Xcode 8.3.2 playground 实时视图渲染不工作

Xcode 8.3.2 playground live view rendering doesn't work

此代码在 Xcode 的先前版本中运行良好,但现在不显示任何内容。它只显示 activity 指示符 "Running project"

import UIKit
import PlaygroundSupport

let container = UIView()
container.frame.size = CGSize(width: 215.0, height: 215.0)

var view = UIView()
view.frame.size = CGSize(width: 185.0, height: 185.0)
view.center = container.center
view.layer.cornerRadius = view.frame.size.height/2
view.backgroundColor = UIColor.white

container.addSubview(view)

let scaleAnimation = CABasicAnimation(keyPath: "transform.scale")
scaleAnimation.fromValue = CGFloat(0.6)
scaleAnimation.toValue = CGFloat(1.15)
scaleAnimation.timingFunction = CAMediaTimingFunction(name:    kCAMediaTimingFunctionEaseOut)
scaleAnimation.isRemovedOnCompletion = false

let opacityAnimation = CABasicAnimation(keyPath: "opacity")
opacityAnimation.fromValue = CGFloat(0.0)
opacityAnimation.toValue = CGFloat(0.1)
opacityAnimation.duration = 1
opacityAnimation.isRemovedOnCompletion = false
opacityAnimation.autoreverses = true;


let circleAnimations: CAAnimationGroup = CAAnimationGroup()
circleAnimations.duration = 2
circleAnimations.repeatCount = HUGE;
circleAnimations.animations = [scaleAnimation, opacityAnimation];

view.layer .add(circleAnimations, forKey: "circleAnimations")

PlaygroundPage.current.liveView = container
PlaygroundPage.current.needsIndefiniteExecution = true

有什么问题吗?

您需要启用助理编辑器才能看到结果。

查看 > 助理编辑器 > 显示助理编辑器

另见此处:

有时关闭 playground 并重新启动 Xcode 即可解决问题