1

I'm trying to create a scrollview with paging that is smaller than the screen size to snap between the buttons in my scrollview. After much headache and searching I found a solution to create the custom paging size explained below. The problem is the buttons inside my scrollview aren't clickable because the hitTest is overriding it?

This answer solves half the problem https://stackoverflow.com/a/6948934/12264367 ... the code works to create the snapping effect but my buttons aren't clickable I'm guessing because the hitTest but I'm not sure how to fix that?

-(UIView *) hitTest:(CGPoint) point withEvent:(UIEvent *)event
{     
    UIView* child = [super hitTest:point withEvent:event]; 
    if (child == self && self.subviews.count > 0)  
    {
        return self.subviews[0];
    }
    return child;
}
DonMag
  • 69,424
  • 5
  • 50
  • 86
IamRob
  • 35
  • 6
  • Did you look at other answers in the question you linked? Several mentioned that the accepted answer prevented buttons from working and those other answers solved the problem with buttons. – HangarRash Dec 15 '22 at 03:32
  • I couldn't find anyone else using buttons on their scrollview – IamRob Dec 15 '22 at 20:26
  • @IamRob - need a little more detail on exactly what you're trying to do... Is this the idea? https://i.stack.imgur.com/skxiS.png --- so you want the "pages" to "snap" to the center of the red-outline box? If so, **one page at a time**, or normal scroll view swipe deceleration? Should the "pages" that are outside of that box be "touchable"? That is, looking at the top, can the user drag from page 5, or only drag within the red-outline box? If the pages have buttons, should the buttons be active if the page is outside the center box, or only when it **is** the center page? – DonMag Dec 15 '22 at 21:48
  • @IamRob Every answer using the UIScrollView delegate method `scrollViewWillEndDragging:withVelocity:` is far better than overriding `hitTest`. – HangarRash Dec 16 '22 at 00:34
  • I'm trying to create an interface like the ios app funveo @DonMag, it has a scrollview of small icons like 150x150 and they snap to the center. – IamRob Dec 16 '22 at 02:03
  • @HangarRash I will look into this more, thanks – IamRob Dec 16 '22 at 02:04
  • @IamRob - Please review [ask]. Lots of folks around here like to offer help, but are not so inclined to go install some other app and try to guess what you're talking about. You didn't answer my questions, so I still don't know what your goal is. Try describing - ***in detail*** - what you want to do. Provide mocked-up images if that helps. Quite often, when someone takes the time to think it through while writing it up, they end up answering the question in the process. – DonMag Dec 16 '22 at 04:36
  • @IamRob - as a side note... If you're talking about *"a scrollview of small icons like 150x150 and they snap to the center"* ... it's very possible (I'd say likely) that is done with a collection view, not a scroll view. – DonMag Dec 16 '22 at 14:50
  • ok thanks i will look into that @DonMag and yeah I understand I will create a better example if the collectionview doesnt work – IamRob Dec 17 '22 at 05:19

0 Answers0