I have an array of pictures that are past to an imageView on a new ViewController. I'm able to have my pageControl show the dots, but they do not animate when I swipe to the next picture. Any ideas on what I am missing as I cannot figure it out? Thanks!
import UIKit
import GoogleMobileAds
class imageViewController: UIViewController,GADBannerViewDelegate, UIGestureRecognizerDelegate, UIScrollViewDelegate {
var bannerView: GADBannerView!
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var myImageView: UIImageView!
@IBOutlet weak var pageControl: UIPageControl!
var passedImage : UIImage! = nil
var passedArray : [UIImage]!
var index = 0
override func viewDidLoad(){
super.viewDidLoad()
self.myImageView.image = passedArray.first
scrollView.minimumZoomScale = 1.0
scrollView.maximumZoomScale = 5.0
configurePageControl()
//---------ADS----------------
// In this case, we instantiate the banner with desired ad size.
bannerView = GADBannerView(adSize: kGADAdSizeBanner)
addBannerViewToView(bannerView)
}
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return myImageView
}
func configurePageControl() {
self.pageControl.numberOfPages = passedArray.count
self.pageControl.currentPage = 0
self.pageControl.pageIndicatorTintColor = UIColor.black
self.pageControl.currentPageIndicatorTintColor = UIColor.red
self.view.addSubview(pageControl)
}
@IBAction func pictureswipe(_ sender: Any) {
let pictureString = self.passedArray[index]
self.myImageView.image = pictureString
index = (index < passedArray.count-1) ? index+1 : 0
}
@IBAction func pictureswipeback(_ sender: Any) {
let pictureString = self.passedArray[index]
self.myImageView.image = pictureString
index = (index > passedArray.count+1) ? index-1 : 0
}
You need to update your pageControl
's currentPage
with your new index as well, try to update your IBAction
methods as following.
@IBAction func pictureswipe(_ sender: Any) {
let pictureString = self.passedArray[index]
self.myImageView.image = pictureString
self.pageControl.currentPage = index
index = (index < passedArray.count-1) ? index+1 : 0
}
@IBAction func pictureswipeback(_ sender: Any) {
let pictureString = self.passedArray[index]
self.myImageView.image = pictureString
self.pageControl.currentPage = index
index = (index > passedArray.count+1) ? index-1 : 0
}