4
votes

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.

5
When you say above do you mean vertically or on top of?Ian1971
I meant on top of it. sorry for the misunderstanding.danielreiser
You need to specify what behavior you want. Eiko asked you this on April 4th and you've been online leaving comments since then, but yet you still haven't answered.Erik B
@rdesign Did you solve this problem? Most of the answers authors did not understand you right...Dima Deplov

5 Answers

12
votes

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).

1
votes

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:]?

1
votes

It's kinda hard to understand what you're trying to achieve. Do you want to scroll through the button or not?

So start dragging inside the button will effect the button, not the scroll view.

It's not clear if that's the behavior you want or the behavior you're trying to change.

If it's the former Eiko's answer is correct and if it's the later you should add the button as a subview of the scroll view and update its frame whenever scrollViewDidScroll: is called. I've never tried this, but it works in theory.

0
votes

Move the whole Scroll View down by the height of your Button and shrink it's height by the same amount. Then put your Button above the the Scroll View - so it's not a child of the Scroll View.

0
votes

If you add simple button in a view then if u touch on button. it will calls Action of it.

Sameway

If you add simple button in a ScroolView then if u touch on button. it will calls Action of it.

And if u touch on the empty area of scroolview then the delegate methods are called of UIScrollView.

If you put your finger on button and Drag it will obviosly effect on the scrollview. scrollview will drag 100%