Swift Playgrounds中的观看次数有限 [英] Limited number of views in Swift Playgrounds

查看:83
本文介绍了Swift Playgrounds中的观看次数有限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建要在 iPad应用上使用的新的 Swift Playground /.playgroundbook时,我经常收到错误消息:

When creating a new Swift Playground / .playgroundbook intended to be used on the iPad App, I often received the error message:

问题正在运行的游乐场.在运行该游乐场时遇到问题.请检查您的代码是否有错误."

我可以追溯到将某些子视图添加到实时视图时引起的此问题.更准确地说,我的目标是将UIImage分为多个部分并为其创建新的UIImageViews:

I could track this issue down to be caused when adding certain subviews to my live view. To be more precise, my goal is to split a UIImage into multiple parts and create new UIImageViews for them:

for x in 0..<parts {
    for y in 0..<parts {
        //Create UIImageView with cropped image
        let pieceView = UIImageView.init(frame: CGRect.init(x: CGFloat(x)*singleSize.width, y:CGFloat(y)*singleSize.height, width: singleSize.width, height: singleSize.height))
        let imageRef = image.cgImage!.cropping(to: CGRect.init(x:0, y:0, width: 100, height: 100));
        pieceView.image = UIImage.init(cgImage: imageRef!)
        //Add them to an array
        self.viewArray.append(pieceView)
    }
}

这对我来说变得很棘手:现在添加7个UIImageViews可以正常工作了.但是,一旦我要添加8个或更多,游乐场就会停止工作,并显示错误消息问题正在运行游乐场..."(请参见上文)

And that's where things become very tricky for me: Adding 7 of these UIImageViews now works without a problem. But as soon as I want to add 8 or more of them, the playground stops working and gives the error message "Problem running playground..." (see above)

我到目前为止测试的内容:

What I tested so far:

  • 添加具有相同图像的UIImageViews不会导致此问题
  • 在后台线程中裁剪UIImage并在主线程上添加视图也无济于事
  • 创建UIImageViews而不将其添加到实时视图不会引起任何问题
  • 无论在何人视图中添加代码,该代码在Mac操场上执行时都能很好地运行

推荐答案

我在添加多个UI元素时遇到了这种iPad Swift Playground运行时错误.

I experienced this kind of iPad Swift Playground run-time error while adding multiple UI elements.

由默认设置启用结果"引起的问题.在设置为开"的游乐场属性中. 启用结果"预览所有嵌入式对象结果的查看器.当您生成许多UI元素时,它会使迅速的操场崩溃.

The problem caused by the default setting of "Enable Results" in the playground's property which is set to be ON. The "Enable Results" previews all the in-line object results' viewer. It makes the swift playground crashed when you produce many UI elements.

尝试禁用启用结果".这个对我有用.

Try to disable the "Enable Results". It works for me.

这篇关于Swift Playgrounds中的观看次数有限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆