将UIImageView添加到UIScrollView以编程方式缩放图像

时间:2018-07-31 05:13:03

标签: swift uiscrollview uiimageview autolayout

我正在METHOD NOT ALLOWED内构建“用户个人资料”页面,可重用视图的顶部是带有用户图像的from django.views import View from django.http import HttpResponse class MessagePassing(View): def get(self, request, *args, **kwargs): return HttpResponse("This is GET method") def post(self, request, *args, **kwargs): return HttpResponse("This is POST method") def patch(self, request, *args, **kwargs): return HttpResponse("This is PATCH method") def put(self, request, *args, **kwargs): return HttpResponse("This is PUT method") UICollectionReusableView已编程(正常工作)在用户图像之间水平滚动。问题是我添加到UIScrollView的第一张图像(封面图像)被放大了。

下面的代码显示了我的程序实现:

scrollview

添加到ReusableView

scrollview

我尝试过的事情

  1. 更改override init(frame: CGRect) { super.init(frame: frame) setupView() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setupView() } override func awakeFromNib() { super.awakeFromNib() } private let scrollView: UIScrollView = { let view = UIScrollView() view.contentMode = .scaleAspectFit view.isUserInteractionEnabled = true view.backgroundColor = UIColor(hexString: COLLECTION_VIEW_BACKGROUND_COLOR)! view.isScrollEnabled = true view.alwaysBounceHorizontal = true view.translatesAutoresizingMaskIntoConstraints = false view.isPagingEnabled = true return view }() private var coverImage: UIImageView = { let view = UIImageView() view.contentMode = .scaleAspectFill view.isUserInteractionEnabled = true view.translatesAutoresizingMaskIntoConstraints = false view.clipsToBounds = true return view }() 中的private func setupView() { backgroundColor = UIColor.white // ScrollView delegate scrollView.delegate = self // Scroll View Init addSubview(scrollView) scrollView.topAnchor.constraint(equalTo: self.topAnchor, constant: 0).isActive = true scrollView.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 0).isActive = true scrollView.rightAnchor.constraint(equalTo: self.rightAnchor, constant: 0).isActive = true scrollView.heightAnchor.constraint(equalToConstant: 350).isActive = true scrollView.contentSize = CGSize(width: self.frame.size.width, height: 350) // Cover Image init scrollView.addSubview(coverImage) coverImage.frame = scrollView.frame } ZoomScaleZoomMin
  2. 在添加ZoomMax之后设置ScrollView的{​​{1}}。
  3. 使用contentSizescrollView(。ImageView等)中的contentMode
  4. 在设置ImageView的图像后,将ImageView添加为ScrollView的子视图
  5. 在所有Init方法中一次调用scaleAspectFit,一次只调用一个Init方法
  6. 更改ImageView的{​​{1}}并尝试多种将其锚定到视图的方法

    我仅从第4点和第6点看到了明显的变化,但没有任何变化。我还查看了该站点上在ScrollView中存在类似问题的其他答案,但是所有解决方案均无效。

在我使用情节提要时,请先感谢任何可以提供帮助的人,此问题并未发生。

0 个答案:

没有答案