滑动到下一张图片时,PageControl 不设置动画
PageControl dosn't animate when swiping to next picture
我有一组图片,这些图片已传到新 ViewController 上的 imageView。我可以让我的 pageControl 显示这些点,但是当我滑动到下一张图片时它们没有动画。由于无法弄清楚,我对我缺少的东西有什么想法吗?谢谢!
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
}
您还需要使用新索引更新您的 pageControl
的 currentPage
,尝试按以下方式更新您的 IBAction
方法。
@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
}
我有一组图片,这些图片已传到新 ViewController 上的 imageView。我可以让我的 pageControl 显示这些点,但是当我滑动到下一张图片时它们没有动画。由于无法弄清楚,我对我缺少的东西有什么想法吗?谢谢!
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
}
您还需要使用新索引更新您的 pageControl
的 currentPage
,尝试按以下方式更新您的 IBAction
方法。
@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
}