スクロールビューを使っていてその下に丸いポチポチ
をつけて、現在の画面位置を確認したいと考えていて
UIPageControlを使っています。
しかし、このコードを打ってもなぜかポチポチUIPageControlは
動いてくれず、一つ目のスクロールビューを示す状態になっています。
そのコードは
import UIKit
class ViewController: UIViewController, UIScrollViewDelegate{
private var pageControl: UIPageControl! private var scrView_right: UIScrollView! override func viewDidLoad() { scrView_right = UIScrollView(frame:CGRectMake(481,0,543,768))//ScrollViewの1ページ分のサイズ + 表示位置 scrView_right.contentSize = CGSizeMake(543*4,768)//全体のサイズ scrView_right.pagingEnabled = true view.addSubview(scrView_right) let back_image1 = UIImageView(frame: CGRectMake(0,0,543,768)) back_image1.backgroundColor = UIColor.magentaColor() scrView_right.addSubview(back_image1) let back_image2 = UIImageView(frame: CGRectMake(543,0,543,768)) back_image2.backgroundColor = UIColor.blackColor() scrView_right.addSubview(back_image2) let back_image3 = UIImageView(frame: CGRectMake(1086,0,543,768)) back_image3.backgroundColor = UIColor.greenColor() scrView_right.addSubview(back_image3) let back_image4 = UIImageView(frame: CGRectMake(1629,0,543,768)) back_image4.backgroundColor = UIColor.yellowColor() scrView_right.addSubview(back_image4) self.view.backgroundColor = UIColor.cyanColor() let pageSize = 5 // 縦方向と、横方向のインディケータを非表示にする. scrView_right.showsHorizontalScrollIndicator = false scrView_right.showsVerticalScrollIndicator = false scrView_right.delegate = self view.addSubview(scrView_right) // PageControlを作成する. pageControl = UIPageControl(frame: CGRectMake(481, self.view.frame.maxY - 100, 543, 50)) pageControl.backgroundColor = UIColor.orangeColor() // PageControlするページ数を設定する. pageControl.numberOfPages = pageSize // 現在ページを設定する. pageControl.currentPage = 0 pageControl.userInteractionEnabled = false self.view.addSubview(pageControl) } func scrollViewDidEndDecelerating(scrollView: UIScrollView) { // スクロール数が1ページ分になったら時. if fmod(scrView_right.contentOffset.x, scrView_right.frame.maxX) == 543 { // ページの場所を切り替える. pageControl.currentPage = Int(scrView_right.contentOffset.x / scrView_right.frame.maxX) } }
}
です。至急お教授お願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/29 06:12