Swice UIScrollView не вызывает функцию "doscroll"

Мой scrollview не будет называть его функцией viewdidscroll... Я уверен, что мой код "правильный". Поэтому я боюсь, что есть какой-то вариант в панели раскадровки. Не собираюсь публиковать скриншоты всего, что у меня есть. Поэтому я надеюсь, что у кого-то была такая же проблема.

Есть идеи?

Это приложение iphone ios в быстром режиме.

import UIKit

class ViewController: UIViewController, UIScrollViewDelegate {

 @IBOutlet var scrollView: UIScrollView!


 var imageGroup : [UIImage?] = []
 var containerViews : [UIImageView?] = []
 var containerView :UIImageView?
 var imgWidthMult : CGFloat = 2.121875
 let imageGroupCount : CGFloat?
 let containerHeight : CGFloat?
 let containerWidth : CGFloat?
 var imageCounter : Int = 0



 override func viewDidLoad() {
 super.viewDidLoad()
 // 1
 imageGroup = [
 UIImage(named: "bg_001")!,
 UIImage(named: "bg_002")!,
 UIImage(named: "bg_003")!,
 UIImage(named: "bg_004")!,
 UIImage(named: "bg_005")!,
 UIImage(named: "bg_006")!,
 UIImage(named: "bg_007")!,
 UIImage(named: "bg_008")!,
 UIImage(named: "bg_009")!,
 UIImage(named: "bg_010")!,
 UIImage(named: "bg_011")!,
 UIImage(named: "bg_012")!,
 UIImage(named: "bg_013")!,
 UIImage(named: "bg_014")!,
 UIImage(named: "bg_015")!,
 UIImage(named: "bg_016")!,
 UIImage(named: "bg_017")!,
 UIImage(named: "bg_018")!,
 UIImage(named: "bg_019")!,
 UIImage(named: "bg_020")!
 ]

 let imageGroupCount = CGFloat(imageGroup.count)
 println(imageGroupCount)


 // 3
 for i in 0..<imagegroup.count 0="" 4="" 5="" {="" containerviews.append(nil)="" }="" let="" imagesscrollviewsize="UIScreen.mainScreen().applicationFrame;" scrollview.contentsize="CGSizeMake(imagesScrollViewSize.height" *="" imgwidthmult="" cgfloat(imagegroup.count),="" imagesscrollviewsize.height)="" containerframe="UIScreen.mainScreen().applicationFrame;" containerheight="" :="" cgfloat="containerframe.height" containerwidth="" containerheight)="" loadvisibleimages()="" println("containerwidth")="" println(containerwidth)="" println(containerframe.size)="" println(scrollview.contentsize)="" return="" this="" loads="" images="" and="" should="" be="" adjusted="" taken="" out="" of="" local="" scope="" func="" loadimage="" (imagecounter:int)="" if="" imagecounter="" <="" ||="">= imageGroup.count {
 // If it outside the range of what you have to display, then do nothing
 return
 }

 // 1
 if let containerView = containerViews[imageCounter] {
 // Do nothing. The view is already loaded.
 } else {
 // 2
 var frame = UIScreen.mainScreen().applicationFrame;
 frame.origin.x = frame.size.height * CGFloat(imageCounter) * 2.121875
 frame.origin.y = 0.0
 frame.size = CGSize(width: containerWidth, height: containerHeight)

 // 3
 var newcontainerView = UIImageView(image: imageGroup[imageCounter])
 newcontainerView.contentMode = .ScaleAspectFit
 newcontainerView.frame = frame
 scrollView.addSubview(newcontainerView)


 containerViews[imageCounter] = newcontainerView
 }

 }

 func purgeImage(imageCounter:Int) {

 if imageCounter < 0 || imageCounter >= imageGroup.count {
 // If it outside the range of what you have to display, then do nothing
 return
 }

 // Remove a page from the scroll view and reset the container array
 if let containerView = containerViews[imageCounter] {
 containerView.removeFromSuperview()
 containerViews[imageCounter] = nil
 }

 }


 func loadVisibleImages() {


 // First, determine which page is currently visible
 let containerframe = UIScreen.mainScreen().applicationFrame;
 let containerHeight : CGFloat = containerframe.height
 let containerWidth : CGFloat = (imgWidthMult * containerHeight)
 let pageWidth = (containerWidth * 2.121875)
 let imageCounter = Int(floor(scrollView.contentOffset.x / pageWidth))


 println(imageCounter)

 // Update the page control

 // Work out which pages you want to load
 let firstPage = imageCounter - 1
 let lastPage = imageCounter + 1


 // Purge anything before the first page
 for var index = 0; index < firstPage; ++index {
 purgeImage(index)
 }

 // Load pages in our range
 for var index = firstPage; index <= lastPage; ++index {
 loadImage(index)
 }

 // Purge anything after the last page
 for var index = lastPage+1; index < imageGroup.count; ++index {
 purgeImage(index)
 }
 println("loadVisibleImages")
 }





 func scrollViewDidScroll(scrollView: UIScrollView) {
 // Load the pages that are now on screen
 println("did scroll")
 loadVisibleImages()
 println("did scroll")

 }




 override func didReceiveMemoryWarning() {
 super.didReceiveMemoryWarning()
 // Dispose of any resources that can be recreated.
 }

}
</imagegroup.count>
1 ответ

Вам необходимо назначить контроллер вида в качестве делегата представления прокрутки. Где-то в вашем viewDidLoad добавьте:

scrollView.delegate = self

licensed under cc by-sa 3.0 with attribution.