現在scrollviewについて勉強しております
import UIKit class ViewController: UIViewController { var img: [UIImage] = [] var imageView01: [UIImageView?] = [] @IBOutlet weak var scrollView: UIScrollView! @IBOutlet weak var imageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // 画像配列を設定 img = [UIImage(named:"img1.png")!, UIImage(named:"img2.png")!, UIImage(named:"img3.png")!] // UIImageViewにUIIimageを追加 imageView01 = [UIImageView(image:img[0]), UIImageView(image:img[1]), UIImageView(image:img[2])] // 全体のサイズ ScrollViewフレームサイズ取得 let scrollViewSize = scrollView.frame.size // 画像サイズ x 3 高さ CGSizeMake(240*3, 240) scrollView.contentSize = CGSize(width:scrollViewSize.width * CGFloat(img.count), height:scrollViewSize.height) //UIImageViewのサイズと位置を決めます //左右に並べる for i in 0...2 { var x:CGFloat = 0 let y:CGFloat = 0 let width:CGFloat = 240 let height:CGFloat = 240 if i == 0 { //x = 0 } else if i == 1 { x = 240 } else if i == 2 { x = 480 } // Scrollviewに追加 imageView01[i]!.frame = CGRect(x:x, y:y, width:width, height:height) // Scrollviewに追加 scrollView.addSubview(imageView01[i]!) } // 1ページ単位でスクロールさせる scrollView.isPagingEnabled = true //scroll画面の初期位置 scrollView.contentOffset = CGPoint(x:0, y:0); } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
このようにしたのですが、スクロールして画像を切り替えることができません
Paging Enabledにチェックしております
原因を教えてくださると幸いです
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/07/22 22:37
2017/07/23 00:31 編集
退会済みユーザー
2017/07/23 02:43