ios - 向 UIDynamicAnimator 添加超过 32 个 UIFieldBehaviors 会导致 SIGABRT

标签 ios swift uikit uikit-dynamics uidynamicanimator

我有以下代码。当我迭代 25 次 (5 * 5) 时,它工作正常。当我迭代 36 次时(for 循环中为 6 * 6),它因 SIGABRT 而崩溃。我已经粘贴了错误的图像(Xcode 中的 Playgrounds 不允许我复制粘贴它)。这是一个内部错误,某处定义了 32 个行为的限制,还是我的代码中的错误?谢谢! enter image description here

//: A UIKit based Playground for presenting user interface

import UIKit
import PlaygroundSupport

class MyViewController : UIViewController {
    var animator : UIDynamicAnimator!

    var springfields : [UIFieldBehavior] = []

    override func loadView() {
        let view = UIView()
        view.backgroundColor = .white
        animator = UIDynamicAnimator(referenceView: view)

        for i in 1...6 {
            for j in 1...6 {
                let newView = UIView()
                let dotwidth = 12
                newView.layer.cornerRadius = CGFloat(dotwidth/2);
                newView.frame = CGRect(x:20+i*25, y:20+j*25, width:dotwidth, height:dotwidth)
                newView.clipsToBounds = true
                newView.backgroundColor = .black

                let newSpringField = UIFieldBehavior.springField()
                springfields.append(newSpringField)
                newSpringField.addItem(newView)
                newSpringField.position = newView.center

                view.addSubview(newView)

                animator.addBehavior(newSpringField)
            }
        }

        self.view = view
    }
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
PlaygroundPage.current.needsIndefiniteExecution = true

最佳答案

在应用程序中运行您的代码,调试控制台输出为:

*** Terminating app due to uncaught exception 'Invalid Association', reason: 'UIDynamicAnimator supports a maximum of 32 distinct fields'

关于ios - 向 UIDynamicAnimator 添加超过 32 个 UIFieldBehaviors 会导致 SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51270700/

相关文章:

iOS 可访问性表示在 3g 上没有互联网连接时可访问

iphone - 核心数据的预填充版本?

iOS 导航栏标题动态设置在 View 出现时在文本中制作省略号

ios - Swift:NSBundle 在尝试设置为 filePath 时总是设置为 nil

ios - 获取具有 alpha 值的纯色版本,同时考虑下面的颜色

ios - UIBarButtonItem 字体在导航后恢复

iPhone 应用程序崩溃在后台被杀死

iphone - initWithNibName 未按预期工作

ios - 如何在 facebook ios 中获取访问 token

swift - 如何在 UITableView 中使用多标签?