हैलो मेरे पास UICollectionView
क्षैतिज छवि प्रविष्टि कोड है, मैं छवियों को स्क्रॉल करते समय PageControl
जोड़ना चाहता हूं, मैंने पेजcontrol चयनकर्ता और IBOutlet
जोड़ा, लेकिन, मैं इसे कैसे एकीकृत कर सकता हूं? के बीच। ?UICollectionView छवि स्क्रॉलिंग के अंदर पेजकंट्रोल कैसे जोड़ें
नीचे दिए गए मेरे कोड।
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet weak var View : DesignableView!
@IBOutlet var collectionView: UICollectionView!
@IBOutlet var collectionViewLayout: UICollectionViewFlowLayout!
@IBOutlet open weak var pageControl: UIPageControl? {
didSet {
pageControl?.addTarget(self, action: #selector(ViewController.pageChanged(_:)), for: .valueChanged)
}
}
override func viewDidLoad() {
super.viewDidLoad()
pageControl?.numberOfPages = 11
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 11;
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: ImageCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCollectionViewCell", for: indexPath) as! ImageCollectionViewCell
cell.label.text = "Cell \(indexPath.row)"
cell.backgroundImageView.image = UIImage(named: "Parallax \(indexPath.row + 1)")
// Parallax cell setup
cell.parallaxTheImageViewScrollOffset(self.collectionView.contentOffset, scrollDirection: self.collectionViewLayout.scrollDirection)
return cell
}
@IBAction open func pageChanged(_ sender: UIPageControl) {
print(sender.currentPage)
}
// MARK: Delegate
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return collectionView.bounds.size;
}
// MARK: Scrolling
func scrollViewDidScroll(_ scrollView: UIScrollView) {
// Parallax visible cells
for cell: ImageCollectionViewCell in collectionView.visibleCells as! [ImageCollectionViewCell] {
cell.parallaxTheImageViewScrollOffset(self.collectionView.contentOffset, scrollDirection: self.collectionViewLayout.scrollDirection)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
दोस्त pagecontrol साथ काम न जब मैं समारोह collectionView (_ collectionView: UICollectionView, numberOfItemsInSection अनुभाग: इंट) जोड़ा -> इंट { वापसी आत्म .myarray.count // यहां पृष्ठ नियंत्रण नहीं है } – SwiftDeveloper
ऐसा इसलिए है क्योंकि प्रत्येक आइटम के लिए पृष्ठ बनाने के लिए, आपको पंक्तियों का उपयोग करना होगा, पंक्तियों –
पर नहीं, लेकिन इस समाधान के साथ, जब उपयोगकर्ता अगले पृष्ठ पर स्वाइप करता है और फिर अपनी उंगली उठाए बिना फिर से वापस स्वाइप करता है, पेज नियंत्रण गलत पृष्ठ दिखाता है। मुझे लगता है कि आपको @ ल्यूक के उत्तर – gasparuff