Swift: Buttons not working inside UIScrollView
<p>I have a ScrollView. You can scroll but the buttons don't allow you to press them(when you press them they don't do anything). Can you help fix this? Here is my current code:</p>

<p>PS: I'm checking this regularly so if you have a question I'll answer.</p>

<pre><code>class ViewController: UIViewController {





    @IBOutlet weak var categoryScrollView: UIScrollView!




    var categoryArr = ["Button1","Button2","Button3","Button4","Button5", "Button 6", "Button 7", "Button 8", "Button 9", "Button 10", "Button 11", "Button 12"]
    var buttonColors = [UIColor.greenColor(), UIColor.blueColor(), UIColor.blackColor(), UIColor.cyanColor(), UIColor.magentaColor(), UIColor.greenColor(), UIColor.blueColor(), UIColor.blackColor(), UIColor.cyanColor(), UIColor.magentaColor(), UIColor.blackColor(), UIColor.brownColor()]
    var buttonImages = [UIImage(named: "One"), UIImage(named: "Two"), UIImage(named: "Three"), UIImage(named: "PlayButtonImage"), UIImage(named: "Triangle"), UIImage(named: "PlayButtonImage"), UIImage(named: "Triangle"), UIImage(named: "PlayButtonImage"), UIImage(named: "Triangle"), UIImage(named: "PlayButtonImage"), UIImage(named: "Triangle"), UIImage(named: "PlayButtonImage")]


    let kPadding:CGFloat = 20


    override func viewDidLoad() {
        super.viewDidLoad()



        let buttonSize = CGSizeMake(categoryScrollView.bounds.size.width/2, categoryScrollView.bounds.size.height/2)//hal

        let scrollingView = ImageButtonsView(buttonSize, buttonCount: 12)
        categoryScrollView.contentSize = scrollingView.frame.size
        categoryScrollView.addSubview(scrollingView)
        categoryScrollView.showsVerticalScrollIndicator = false
        categoryScrollView.delegate = self
        categoryScrollView.pagingEnabled = true
        categoryScrollView.indicatorStyle = .Default
        categoryScrollView.contentOffset = CGPointMake(0, 0)
        categoryScrollView.delaysContentTouches = false
        categoryScrollView.userInteractionEnabled = true;
        categoryScrollView.exclusiveTouch = true;
        categoryScrollView.canCancelContentTouches = true;
        //categoryScrollView.clipsToBounds = true

    }


    func ImageButtonsView(buttonSize:CGSize, buttonCount:Int) -&gt; UIView {




        let buttonView = UIView()
        buttonView.frame.origin = CGPointMake(50,142)
        let padding = CGSizeMake(kPadding, kPadding)
        buttonView.frame.size.width = (buttonSize.width + padding.width) * CGFloat(buttonCount)
        var buttonPosition = CGPointMake(0, padding.height)
        let buttonIncrement = buttonSize.width + padding.width
        for i in 0...(buttonCount - 1)  {


            let button = UIButton(type: .Custom)

            buttonView.userInteractionEnabled = true

            button.frame.size = buttonSize
            button.frame.origin = buttonPosition
            buttonPosition.x = buttonPosition.x + buttonIncrement
            button.setTitle(categoryArr[i], forState: UIControlState.Normal)
            let buttonImagesOne = buttonImages[i]
            button.setImage(buttonImagesOne, forState: .Normal)
            button.layer.cornerRadius = 30
            button.addTarget(self, action: "pressed:", forControlEvents: UIControlEvents.TouchUpInside)
            buttonView.addSubview(button)









        }
        //buttonView.backgroundColor = UIColor.redColor()
        categoryScrollView.bringSubviewToFront(buttonView)


        return buttonView

    }


}




extension ViewController:UIScrollViewDelegate{
    func scrollViewDidEndDecelerating(scrollView: UIScrollView) {





        let index = round(scrollView.contentOffset.x / scrollView.frame.size.width)
        print(index)
    }



    func pressed(/*sender: UIButton!*/) {

        let vc = UIViewController(nibName: "GridViewController", bundle: nil)
        self.presentViewController(vc, animated: true, completion:nil)

        //viewController.hidden = true






    }
</code></pre>

<p>}</p>