2

I have an application I'm making in storyboards. I want to have a tutorial-type of view. I decided to go with a freeform view controller and am filling it with 600x600 views that count as the pages. The problem I'm having is that when I have a UI button animate to the next page, the buttons that were created outside of the visible view don't seem to work. I even moved a view over so the button was half-visible and only half the button works when I move the view over.

Here's my next page code:

- (void)nextPage {
    if (scrolling) return;
    scrolling = YES;

    [UIView animateWithDuration:0.3 animations:^{
        CGRect frame = self.tutorialView.frame;
        frame.origin.x -= 50; //frame.size.width;
        [self.tutorialView setFrame:frame];
    }];

    scrolling = NO;
}

I currently have it moving only 50px instead of the whole page for testing purposes.

Image1 Image2

For testing purposes, I've started it half-way through and only half the button works. I've started it with the second view on top of the other one halfway visible and the same thing happens (only half the button works). Otherwise, when I tap the next button on the first view the buttons on the second view don't work (buttons created outside the initial view).

AKrush95
  • 1,381
  • 6
  • 18
  • 35

1 Answers1

5

Views don't receive touch events where they're outside the bounds of their superview. You'll need to increase the button's superview's size.

You can visualize this behavior by setting clipsToBounds = YES - then you'll only see the touchable area of your button.

(You can override this behavior, but you probably shouldn't.)

Community
  • 1
  • 1
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
  • Thanks for your fast response. That's strange, though, because I've definitely done this before. Could the difference be that I used a scroll view? – AKrush95 Feb 28 '15 at 23:07
  • Yes, definitely look at using a scroll view or page view controller – Paulw11 Feb 28 '15 at 23:11