Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIImageView没有';t添加到UIScrollView_Ios_Swift_Uiscrollview_Uiimageview - Fatal编程技术网

Ios UIImageView没有';t添加到UIScrollView

Ios UIImageView没有';t添加到UIScrollView,ios,swift,uiscrollview,uiimageview,Ios,Swift,Uiscrollview,Uiimageview,嗨,我有一个通过编程添加的UIScrollView,然后在其中添加一个UIImageView作为子视图,问题是UIImageView没有显示在UIScrollView中 这是我的密码: import UIKit import Foundation class InstagramBigCollectionViewCell: UICollectionViewCell { private let scrollView = UIScrollView() private let instagramIm

嗨,我有一个通过编程添加的UIScrollView,然后在其中添加一个UIImageView作为子视图,问题是UIImageView没有显示在UIScrollView中

这是我的密码:

import UIKit
import Foundation

class InstagramBigCollectionViewCell: UICollectionViewCell {

private let scrollView = UIScrollView()
private let instagramImageThumb = UIImageView()

var urlString: String!

func initialize() {
    scrollView.backgroundColor = UIColor.clearColor()
    self.backgroundColor = UIColor.clearColor()
    instagramImageThumb.backgroundColor = UIColor.redColor()

    scrollView.delegate = self
    scrollView.minimumZoomScale = 1.0
    scrollView.maximumZoomScale = 6.0
    scrollView.userInteractionEnabled = true

    let tap = UITapGestureRecognizer(target: self, action:#selector(self.zoomWhenDoubleTap))
    tap.numberOfTapsRequired = 2
    scrollView.addGestureRecognizer(tap)

    self.addSubview(scrollView)

    scrollView.topAnchor.constraintEqualToAnchor(self.topAnchor).active = true
    scrollView.leadingAnchor.constraintEqualToAnchor(self.leadingAnchor).active = true
   // scrollView.trailingAnchor.constraintEqualToAnchor(self.trailingAnchor).active = true
  //  scrollView.bottomAnchor.constraintEqualToAnchor(self.bottomAnchor).active = true
    scrollView.contentSize = CGSize(width: self.frame.width, height: self.frame.height)

    instagramImageThumb.contentMode = .ScaleAspectFit

    scrollView.addSubview(instagramImageThumb)

    instagramImageThumb.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height)

    print(instagramImageThumb.frame)
   //here we can see that the frame is set as well

 }

func zoomWhenDoubleTap(){
    let scrollViewSize = scrollView.bounds.size
    var rectToZoomTo = CGRect()

    let width = scrollViewSize.width
    let height = scrollViewSize.height
    let x:CGFloat = 0.0
    let y:CGFloat = 0.0
    rectToZoomTo = CGRect(x: x, y: y, width: width, height: height)
    self.scrollView.zoomToRect(rectToZoomTo, animated: true)

    }
}

 extension InstagramBigCollectionViewCell: UIScrollViewDelegate {

func viewForZooming(in scrollView: UIScrollView) -> UIView? {
    return instagramImageThumb
   }
}
知道为什么吗

编辑:UIScrollView的边界已设置,并且框架已存在,但由于某些原因,只是UIImageView未显示在屏幕上

EDIT2:显示所有代码


在UICollectionViewDataSouce的cellForItemAt:中调用initialize,这是什么意思?我正在顶部初始化它,并将其添加到初始化功能的视图中。请显示所有相关代码。这是所有相关代码确定现在我显示所有。。。我尝试了注释选项和未注释选项。。。scrollview的框架如我所述设置并正确显示在屏幕上,UIImageView的框架似乎在那里,但没有显示出来。。。。如前所述above@shallowThought现在呢?