2017-05-05 8 views
0

나는 많은 imageViews가있는 수평 스크롤 가능한 ScrollView가 있습니다. 사용자가 클릭 한 이미지보기를 강조하고 싶지만이를 수행하는 방법을 잘 모르겠습니다. 나는 이미지에 탭 제스처를 추가했습니다 :scrollView 반복하고 clicked imageView를 찾으십시오

let tap = UITapGestureRecognizer(target: self, action: #selector(imgTapped(_:))) 

그러나 미안 여기에서 imgTapped 기능에 무엇을 URE하지 ... 난 각각의 이미지 뷰에 대해 고유 한 태그를 가지고있다.

도움을 주시면 감사하겠습니다. ,

func imgTapped(_ sender: UIGestureRecognizer) { 
    // get the tag for the clicked imageView 
    guard let tag = sender.view?.tag else { return } 

    let imageView = ImageViews.filter { $0.tag == tag }.first 
} 

그렇지 않으면 당신이 당신의 scrollViews subviews을 반복 할 수 코멘트를 체크 아웃하고 코드에 무슨 일이 일어 나는지 : 모든 모음이있는 경우

답변

0

당신의 imageViews 당신이 뭔가를 할 수

func imgTapped(_ sender: UIGestureRecognizer) { 
    // get the tag for the clicked imageView 
    guard let tag = sender.view?.tag else { return } 

    // iterate through your scrollViews subviews 
    // and check if it´s an imageView 
    for case let imageView as UIImageView in self.imageScrollView.subviews { 
     // check if the tag matches the clicked tag 
     if imageView.tag == tag { 
      // this is the tag the user has clicked on 
      // highlight it here 
     } 
    } 
}