Swift 处的 UIPageControl

UIPageControl at Swift

我在我的申请中添加了一个 UIPageController。我从休息服务中填充它,然后单击其中一个页面时,它将直接转到最新的页面。我错过了一些东西,但我无法解决。我怎样才能选择一个而不是最新的。

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.FikirClick))
for item in self.ArrayList {
    say = say + 1
    self.frameFikirImage.origin.x = self.FikirscrollView.frame.size.width * CGFloat(say) + 10
    self.frameFikirImage.origin.y = 55
    self.imgFikirImage = UIImageView(frame: self.frameFikirImage)
    self.FikirscrollView.tag = item.id as! Int
    tapGesture.view?.tag = item.id as! Int

    self.imgFikirImage.sd_setImage(with: URL(string:  item.picture!))
    self.imgFikirImage.contentMode = UIView.ContentMode.scaleAspectFit

    self.FikirscrollView.addSubview(self.imgFikirImage)
    self.frameFikirText.origin.x = self.FikirscrollView.frame.size.width * CGFloat(say) + 25
    self.frameFikirText.origin.y = 190
    self.lblFikir = UILabel(frame: self.frameFikirText)
    self.lblFikir.tintColor = UIColor.white
    self.lblFikir.text = item.adi
    self.lblFikir.font = self.lblFikir.font.withSize(20)
    self.FikirscrollView.addSubview(self.lblFikir)


    self.frameFikirButton.origin.x = self.FikirscrollView.frame.size.width * CGFloat(say) + 20
    self.frameFikirButton.origin.y = 140


    self.FikirscrollView.addGestureRecognizer(tapGesture)
}
self.FikirscrollView.contentSize = CGSize(width:self.FikirscrollView.frame.size.width * pageControlFikir,height: self.FikirscrollView.frame.size.height)

@objc func FikirClick(sender: UITapGestureRecognizer) {
    var tag = sender.view!.tag
    print(tag);
}

手势需要在for循环内

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.FikirClick))

因为它一次只能查看 1 个视图,所以当您单击 var tag = sender.view!.tag 时它会添加到最后 1 个视图,tapGesture.view?.tag = item.id as! Int 更新到循环的最后一个标签

还要确保

self.imgFikirImage.addGestureRecognizer(tapGesture)

并为图像视图启用用户交互