title: using gesture recognizer on a subview of UIScrollView - Swift
body: <p><a href="https://i.stack.imgur.com/63wya.png" rel="nofollow noreferrer">I have attached an image here</a>
  I am a newbie to <code>iOS</code> development. My question is as follows:</p>
  
  <p>I want to swipe my <code>scrollView</code> outside of its width using gesture control. 
  To be precise I want my <code>UIScrollView</code> to scroll when swipe is performed in the <code>subview</code> (there is only one <code>subview</code>).</p>
  
  <p>I have gone through several StackOverflow question but I couldn't quite get a correct answer.</p>
  
  <p>Your help is much appreciated!</p>
  
  <pre><code>class ViewController: UIViewController, UIGestureRecognizerDelegate {
  
  @IBOutlet weak var scrollView: UIScrollView!
  
  var images = [UIImageView]()
  override func viewDidLoad() {
      super.viewDidLoad()
  }
  
  override func viewDidAppear(_ animated: Bool) {
      var contentWidth: CGFloat = 0.0
      for x in 0...2 {
          let image = UIImage(named: "icon\(x).png")
          let imageView = UIImageView(image:image)
          images.append(imageView)
  
          var newX: CGFloat = 0.0
  
          newX = scrollView.frame.size.width/2 + scrollView.frame.size.width * CGFloat(x)
          contentWidth += newX
  
          scrollView.addSubview(imageView)
          imageView.frame = CGRect(x: newX - 75, y: (scrollView.frame.size.height/2) - 75, width: 150, height: 150)
  
      }
      scrollView.clipsToBounds = false
      scrollView.contentSize = CGSize(width: contentWidth, height: view.frame.size.height)
  }
  </code></pre>
  
  <p>As you can see in the image the width of my UIScrollView has a grey background color (I did that to illustrate my point). Now I want to also scroll the scroll view when a user swipes in the subview (non-grey) UIImageView.</p>
  
  <p>I have added the following function and made a return of yes to enable both views to recognize gestures simultaneously. But, I am not getting the desired result. Can anyone take a look?</p>
  
  <pre><code>func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -&gt; Bool {
          return true
      }
  </code></pre>