1

I am trying to reproduce natively the TVML template that provides a grid of clickable images that extends beyond the screen's bounds. I am using a scroll view for this attempt, but I am unable to select elements that are added to the scroll view, but outside its visible area.

The sketch code using buttons for simplicity is as follows:

let dim = 50

for i in 0..<10 {
    for j in 0..<10 {
        let frame = CGRect(x: i * (dim + 10), y: j * (dim + 10), width: dim, height: dim)
        let button = UIButton(type: .System)
        button.frame = frame
        myScrollView.panGestureRecognizer.allowedTouchTypes = [UITouchType.Indirect.rawValue]

        myScrollView.addSubview(button)
    }
}

The scroll view is sized such that only half of these buttons are visible. Why is the scroll view not scrolling to the buttons outside this area (using Siri remote)? I thought the panGesture touchType might help, but it didn't. Am I missing something obvious?

2 Answers 2

1

Set contentSize property to your scrollview. Make sure all components comes under given content size.

    myScrollView.contentSize = CGSizeMake(1880, 2000)
Sign up to request clarification or add additional context in comments.

Comments

0

It would actually be way easier to just use a UICollectionView. If you add an image to each cell, you'll get exactly the behavior you want after adjusting the collection view to what you want.

This tutorial kind of explains how it works. http://www.brianjcoleman.com/tutorial-collection-views-using-flow-layout/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.