ios - UIButtons receiving touch events when added directly to scrollview but not indirectly -
i have 10 uibuttons stacked side side in app , , total dimensions of buttons 640x96.
if add these buttons directly uiscrollview, register touch events , scrollable.
but if try add them plain uiview, add uiview scrollview, dont work.
this code:
- (void)viewdidload { [super viewdidload]; uiview *fview = [[uiview alloc] init]; fview.frame = cgrectmake(0, 0, 640, 96); fview.backgroundcolor = [uicolor blackcolor]; [fview setuserinteractionenabled:yes]; [_sv setuserinteractionenabled:yes]; (int i=0; i<10; i++) { uibutton *button = [uibutton buttonwithtype:uibuttontypecustom]; button.frame = cgrectmake(64*i, 0, 64, 96); [button settitle:@"click me!" forstate:uicontrolstatenormal]; [button addtarget:self action:@selector(buttonclicked:) forcontrolevents:uicontroleventtouchupinside]; [fview addsubview:button]; } [_sv addsubview:fview]; _sv.contentsize = cgsizemake(640, 96); } -(void)buttonclicked:(id)sender { nslog(@"clicked!"); }
while writing question fixed problem :d
all had set frame of uiview before set scrollview's contentsize.
in case:
[_sv addsubview:fview]; fview.frame = cgrectmake(0, 0, 640, 96); // added line _sv.contentsize = cgsizemake(640, 96);
hope helps!
Comments
Post a Comment