davdroman / Popsicle

Simple, extensible interpolation framework
MIT License
1.09k stars 105 forks source link

working with a button across multiple views #13

Closed hsavit1 closed 9 years ago

hsavit1 commented 9 years ago

hey,

I have a button that I anchor to a corner on the first page, and it stays static across 3 separate page views. The button gets anchored fantastically, however it removes itself as a target in the second and third pages. Any idea as to how I can keep it as a functional button?

Thanks!

davdroman commented 9 years ago

Hi.

I'd need more info to evaluate your issue. Are you using DRPageScrollView? If so, did you enable page reuse?

davdroman commented 9 years ago

Hey @hsavit1 did you finally get around with this issue?

hsavit1 commented 9 years ago

Yea I never figured it out actually.

The Button loses its functionality on the second and third pages of the view pager. Will keep you posted if I come up with something

On Monday, June 8, 2015, David Román notifications@github.com wrote:

Hey @hsavit1 https://github.com/hsavit1 did you finally get around with this issue?

— Reply to this email directly or view it on GitHub https://github.com/Dromaguirre/Popsicle/issues/13#issuecomment-109955630 .

Sent from Gmail Mobile

davdroman commented 9 years ago

@hsavit1

Oh my. I just came up with what that's about. Since the page view where the button is contained is out of bounds but the button is still visible, it won't receive touch events. It's a default behavior every UIView component has: they ignore touch events when they're out of bounds from their parent superviews.

Check out this official document from Apple where they explain how to get around it: https://developer.apple.com/library/ios/qa/qa2013/qa1812.html

If for some reasons the existing layout has to be maintained, you can change the hit-testing behavior of the parent view so that it doesn't ignore the touch events. This can be done by overriding the -(UIView *)hitTest:withEvent: method of the parent view's class.

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

    // Convert the point to the target view's coordinate system.
    // The target view isn't necessarily the immediate subview
    CGPoint pointForTargetView = [self.targetView convertPoint:point fromView:self];

    if (CGRectContainsPoint(self.targetView.bounds, pointForTargetView)) {

        // The target view may have its view hierarchy,
        // so call its hitTest method to return the right hit-test view
        return [self.targetView hitTest:pointForTargetView withEvent:event];
    }

    return [super hitTest:point withEvent:event];
}
hsavit1 commented 9 years ago

hey, forgot to respond to this

looks neat! will check out