UIView on top of UITableView -
i have been developing app in have uiviewcontroller, have added uitableview. want add uiview on top of tableview @ fixed position.
i tried following code, uiview scrolls along tableview:
- (void)viewdidload { uiview *view = [[uiview alloc] initwithframe:cgrectmake(250, 100, 50, 50)]; view.backgroundcolor = [uicolor orangecolor]; [_tableview addsubview:view]; [_tableview bringsubviewtofront:view]; } how can prevent uiview scrolling?
well, since uitableview subclass of uiscrollview try implement "floating view". should make sure
- the floating view top view in hierarchy
- the position of floating view should updated when
contentoffsetchanges (so visually float on top of other content when user scrolling)
you can try (assuming floatingheaderviewcenter initial center of floatingview:
- (void)scrollviewdidscroll:(uiscrollview *)scrollview { self.floatingheaderview.center = cgpointmake(floatingheaderviewcenter.x + scrollview.contentoffset.x, floatingheaderviewcenter.y + scrollview.contentoffset.y); [scrollview bringsubviewtofront:floatingheaderview]; } although you'd better have view container 2 subviews: tableview , floating view.
Comments
Post a Comment