swift - Xcode 8.2 Playground 不显示 UIKit 结果

标签 swift xcode swift-playground

我尝试运行一些 UIKit playground 示例,但在查看图形结果时遇到问题。

什么有效:

  1. 我可以在灰色的右侧编辑器 Pane 中预览任何字符串分配。
  2. 我可以点击“眼睛”(快速预览)或“小矩形”图标并查看正确的 UIKit 结果,尽管是在临时弹出窗口或代码行之间的 Pane 中(均较小)。
  3. 我可以打印内容,它会显示在编辑器下方的 Pane 中(在带有时间轴和开始/停止按钮的栏下方)。

什么不起作用:

  1. 我无法以大型图形方式显示我的代码结果。

下面是我尝试使用的一些示例代码:

import UIKit
import PlaygroundSupport

let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 375.0, height: 667.0))


let circle = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 50.0, height: 50.0))
circle.center = containerView.center
circle.layer.cornerRadius = 25.0

let button = UIButton(type: .detailDisclosure)
containerView.addSubview(button)

let startingColor = UIColor(red: (253.0/255.0), green: (159.0/255.0), blue: (47.0/255.0), alpha: 1.0)
circle.backgroundColor = startingColor

containerView.addSubview(circle);

PlaygroundPage.current.liveView = containerView

运行 Playground 还有什么我应该做的吗? 有一个相关问题:Playground not showing results询问 OP 是否在模拟器中设置了设备。好吧,就我而言,我没有,但我不知道该在哪里做。模拟器没有运行。

编辑:

我已经看到标记为可能重复的问题,接受的答案对我不起作用,另一个提到部分解决方案(仅快速和内联预览)。因此,重新表述我的问题:在 Xcode 8.2 中,除了快速预览(弹出窗口)和内联预览(代码行之间)之外,我是否应该期望在其他任何地方看到与 UIView 相关的结果?

最佳答案

我遇到了和你一样的问题。这是我以某种方式解决它的方法。

似乎要进行实时预览(PlaygroundPage.current.liveView),playground 正在启动模拟器。就我而言,它默认打开 iOS 9 设备。我想这是我用过的最后一个。

  1. 我关闭了 playground 的助理编辑器,隐藏了所有内联预览(它们似乎与实时预览冲突),然后完全关闭了 Xcode。
  2. 在模拟器 -> 硬件 -> 设备中,我选择了 iOS 10 设备 enter image description here
  3. 我也关闭了模拟器
  4. 我从 Dock 打开 Xcode(不是直接打开文件)
  5. 我选择了 Playground 开
  6. 我打开了助理编辑器。在您通常看到带有“Running YourPlaygroundName”的加载程序的顶部,您应该看到“Launching the simulator”。它应该会启动您在上面选择的 iOS 10 设备。

希望对你有用

关于swift - Xcode 8.2 Playground 不显示 UIKit 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42348802/

相关文章:

ios - 仅在 GET 请求上出现 Alamofire 请求错误

arrays - 如何确定数组中的所有对象是否在 Swift 中连接

string - 如何获取字符串的最后 4 个字符?

ios - 在 Swift 中将 UIView 转换为 .png

ios - 将 NSArray 拆分为 NSString

ios - iPhone 上的 Swift playground

ios - 在 iOS Swift 项目中从 "2015-01-17T20:00Z"创建 NSDate

iOS:使用CGContextAddLineToPoint绘制多条线

iphone - Exc Bad Access 关闭 View Controller

ios - 相机预览层未显示