Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

‘static‘ UIButton ontop UIScrollview?

I want to achieve a rather simple effect. A scrollView and a static button above it. So far not problem. Unfortunately a problem occurs if I want to scroll the view "trough" the button. So start dragging inside the button will effect the button, not the scroll view.

Any ideas on how to achieve that?

Thanks a lot!

I think this approach won't work because touchesBegan is deprecated in UIScrollView … (Is this info true?)

Not the solution :-)

@implementation MySuperButton

+ (id)buttonWithFrame:(CGRect)frame {
    return [[[self alloc] initWithFrame:frame] autorelease];
}

- (id)initWithFrame:(CGRect)frame {
    if (self == [super initWithFrame:frame]) {
        NSLog(@"initWithFrame");
    }
    return self;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    [self.nextResponder touchesBegan:touches withEvent:event];
    NSLog(@"[self nextResponder]: %@", [self nextResponder]);
}

@end

Unfotunately this does not work, yet. I think the next responder is a my UIView not my UIScrollView. Any ideas?

If my viewcontroller which is the nextResponder, passes the touches to the scrollView, nothing happens aswell.

like image 859
danielreiser Avatar asked Dec 10 '22 09:12

danielreiser


2 Answers

Add the button not to the scroll view but to its parent view, and everything should work just fine. Touches on the button directly will get delivered to the button, and touches on the background (scroll view) will get delivered to the scroll view.

As the button isn't a subview of the scroll view it won't move with the background (which I suppose you mean with static).

like image 102
Eiko Avatar answered Dec 22 '22 20:12

Eiko


I never played alot with the touch events and such, but i'll try to help with my basic understanding anyway.

Try setting the button's exclusiveTouch to NO. Not sure, but maybe enableMultitouch to YES as well.

If that doesn't work i'd try maybe subclassing UIButton, overriding the touch events and passing them to [self nextResponder] before/after [super touchEventX:]?

like image 38
Zaky German Avatar answered Dec 22 '22 22:12

Zaky German