如何以编程方式制作滚动视图时解决此问题?

时间:2016-12-20 10:19:30

标签: ios swift uiimage scrollview

FastNavigator
如何以编程方式制作滚动视图来解决此问题?

class FastNavigator: UIView {

    var scrollView : UIScrollView!
    var scrollSubviews : [UIView]!
    var size :CGFloat = 0

    func configure(subviews:[UIView]){
        scrollSubviews = subviews

        scrollView = UIScrollView(frame: self.frame)
        self.addSubview(scrollView)

        for view in scrollSubviews {

            scrollView.addSubview(view)
            view.frame = CGRect(x: 0 + size  , y: 0, width: scrollView.frame.width, height: scrollView.frame.height)
            size += view.frame.size.width
            print(size)
        }
        scrollView.contentSize = CGSize(width: size, height: scrollView.frame.height)
    }
}

的ViewController

class ViewController: UIViewController {

    let fast = FastNavigator()
    let myImages = ["mahmoud.jpg","ziad.jpg","farah.jpg","zinji.jpg"]


    override func viewDidLoad() {
        super.viewDidLoad()

        var subViews : [UIImageView] = []
        for imageName in myImages {

            let myUIImage = UIImage(contentsOfFile: Bundle.main.path(forResource: imageName, ofType: "")!)
            let imageView = UIImageView(image: myUIImage)
            subViews.append(imageView)
        }
        fast.frame = self.view.frame
        fast.configure(subviews: subViews)
        self.view.addSubview(fast)
    }
}

我总是得到这个

libc ++ abi.dylib:以NSException类型的未捕获异常终止

1 个答案:

答案 0 :(得分:0)

enter image description here

转到断点导航器,单击添加(" +"按钮),"异常断点",RMB,"编辑断点",使用&#添加操作34; po $ arg1"。现在你得到了NSException的打印错误。请在此处发布您的错误。