0
이미지를 클릭 할 수있게 만들고 자세한 내용으로 새보기 컨트롤러에 전달하려고합니다. 내 HomeViewController 내에서 UIPageController와 함께 UIScrollView를 사용하고 있습니다. 연구하려고했지만 구체적인 사례를 찾을 수 없었습니다. 나는 아마 segue와 함께 그것을 통과한다고 생각하고있다. 그러나 나는 방법을 이해할 수 없다. 어떤 아이디어라도 환영합니다. 미리 감사드립니다. 내 코드 :Swift에서 페이지 컨트롤을 사용하여 ScrollView에서 NewViewController로 이미지를 전달하는 방법
class HomeViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet var pageControl: UIPageControl!
@IBOutlet var topScrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
pageScrollView()
}
func pageScrollView() {
self.topScrollView.isUserInteractionEnabled = true
self.topScrollView.addGestureRecognizer(UITapGestureRecognizer())
self.topScrollView.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: 200)
let scrollViewWidth:CGFloat = self.topScrollView.frame.width
let scrollViewHeight:CGFloat = self.topScrollView.frame.height
let imgOne = UIImageView(frame: CGRect(x:0, y:0,width:scrollViewWidth, height:scrollViewHeight))
imgOne.image = UIImage(named: "img1")
let imgTwo = UIImageView(frame: CGRect(x:scrollViewWidth, y:0,width:scrollViewWidth, height:scrollViewHeight))
imgTwo.image = UIImage(named: "img2")
let imgThree = UIImageView(frame: CGRect(x:scrollViewWidth*2, y:0,width:scrollViewWidth, height:scrollViewHeight))
imgThree.image = UIImage(named: "img3")
let imgFour = UIImageView(frame: CGRect(x:scrollViewWidth*3, y:0,width:scrollViewWidth, height:scrollViewHeight))
imgFour.image = UIImage(named: "img4")
let imgFive = UIImageView(frame: CGRect(x:scrollViewWidth*4, y:0,width:scrollViewWidth, height:scrollViewHeight))
imgFive.image = UIImage(named: "img5")
self.topScrollView.addSubview(imgOne)
self.topScrollView.addSubview(imgTwo)
self.topScrollView.addSubview(imgThree)
self.topScrollView.addSubview(imgFour)
self.topScrollView.addSubview(imgFive)
self.topScrollView.contentSize = CGSize(width:self.topScrollView.frame.width * 5, height:self.topScrollView.frame.height)
self.pageControl.currentPage = 0
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
let pageWidth:CGFloat = scrollView.frame.width
let currentPage:CGFloat = floor((scrollView.contentOffset.x-pageWidth/2)/pageWidth)+1
// Change the indicator
self.pageControl.currentPage = Int(currentPage)
}
}