我有以下代码。当我迭代25次(5 * 5)时,它可以正常工作。当我迭代36次(for循环中为6 * 6)时,它会因SIGABRT而崩溃。我已经粘贴了错误的图片(Xcode中的Playgrounds不允许我复制粘贴)。这是内部错误,是否在某处定义了32个行为限制,或者这是我的代码中的错误?谢谢!
ios - 向UIDynamicAnimator添加超过32个UIFieldBehaviors会导致SIGABRT-LMLPHP

//: 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

最佳答案

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

***由于未捕获的异常“无效关联”而终止应用程序,原因:“UIDynamicAnimator最多支持32个不同的字段”

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

10-12 21:34