tags:

views:

48

answers:

2

UIButton inside UIScrollView doesn't fire on tap. Please help resolve it.

 // Add a button
 UIButton *btn1 = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
 btn1.frame = CGRectMake(0, 0, 26, 18); 
 btn1.bounds = CGRectMake(0, 0, 30.0, 30.0); 
 [btn1 setImage:[UIImage imageNamed:@"btnchecked.png"]
                         forState:UIControlStateNormal];
 [btn1 addTarget:self action:@selector(buttonClick1:) 
                      forControlEvents:UIControlEventTouchUpInside];
 [scrollView addSubview:btn1];


- (void)buttonClick1:(id)sender {
     int dd = 4; 
 }
A: 

I found this stuff

But the scrollview will block the touches from the button unless you set userInteractionEnabled and exclusiveTouch properties to NO on the scrollview. But that would defeat the purpose of having a scrollview inside a button I think.

But how to do it?

Dmitry Boyko
A: 

I found this stuff

But the scrollview will block the touches from the button unless you set userInteractionEnabled and exclusiveTouch properties to NO on the scrollview. But that would defeat the purpose of having a scrollview inside a button I think.

But how to do it?

Say you have a UIScrollView *sv ... then

sv.userInteractionEnabled = YES;
sv.exclusiveTouch = YES;

I would also add

sv.canCancelContentTouches = YES;
sv.delaysContentTouches = YES;
leukosaima