希望有人能指出这是怎么回事。

我的故事板有一个名为UIScrollViewtimelineScrollView和一个名为imageviewtest的UIImageView

我正在创建一个简单的直线图像。如果我将其添加到UIImageView中,它将显示正常。但是,如果我将其添加到UIScrollView中,则不会显示任何内容。

如何使其显示在UIScrollView中?

func drawingTest(){

    let drawing = DrawingHelper()
    let imageSize2 = CGSize(width: 100, height: 60)
    let fromPoint: CGPoint = CGPoint(x: 0, y:0)
    let toPoint: CGPoint = CGPoint(x: 50, y:0)


    imageviewtest.image = drawing.drawLine(fromPoint, toPoint: toPoint, imageSize: imageSize2)

    var imageView = UIImageView()
    var image = drawing.drawLine(fromPoint, toPoint: toPoint, imageSize: imageSize2)
    imageView.image = image;


    var scrollViewAreaSize = CGSize(width: 100, height: 60)
    timelineScrollView.contentSize = scrollViewAreaSize
    timelineScrollView.addSubview(imageView)
}

最佳答案

为图像视图设置适当的框架或使用图像初始化UIImageView:

var image = drawing.drawLine(fromPoint, toPoint: toPoint, imageSize: imageSize2)
var imageView = UIImageView(image:image)

documentation:

此方法调整接收器的帧以匹配接收器的大小。
指定的图像。

10-08 05:25