Sunday, 15 June 2014

ios - What view is revealed when panning UITableViewCell? -



ios - What view is revealed when panning UITableViewCell? -

i panning uitableviewcell contentview in code below. know view exists behind uitableviewcell contentview beingness moved?

the reason inquire because want alter color of "revealed view". customize color underneath each tableviewcell when cell swiped. example, if left swipe 3rd row, see bluish behind cell. if left swipe 4th row, see greenish behind cell.

- (void)pangesturerecognizer:(uipangesturerecognizer *)recognizer { //... if ((recognizer.state == uigesturerecognizerstatebegan || recognizer.state == uigesturerecognizerstatechanged) && [recognizer numberoftouches] > 0) { cgpoint location1 = [recognizer locationoftouch:0 inview:self.tableview]; nsindexpath *indexpath = [self.tableview indexpathforrowatpoint:location1]; uitableviewcell *cell = [self.tableview cellforrowatindexpath:indexpath]; cgpoint translation = [recognizer translationinview:self.tableview]; cell.contentview.frame = cgrectoffset(cell.contentview.bounds, translation.x, 0); } //... }

one thing tried create uiview , add together cell behind contentview. works, not satisfaction. if set in code animate cell deletion uitableviewrowanimationleft, color of background move left along cell. makes sense because background view created moves along entire cell when animation moves cell out delete it. behavior want background color behind cell, not move when cell moved in deletion animation.

the next code how add together background view cell , set below contentview.

[cell.contentview setbackgroundcolor:[uicolor whitecolor]]; uiview *view = [[uiview alloc] initwithframe:cgrectmake(0, 0, 320, self.tableview.rowheight)]; view.backgroundcolor = [uicolor redcolor]; [cell addsubview:view]; [cell bringsubviewtofront:cell.contentview];

ah ha!

i found elegant , wonderful solution this. i'm jittering joy.

i added view right of cell.contentview background color want. when swipe cell, rightsideview gets pulled along looks it's view beingness revealed. (now if wanted set content in there, that's complication person... i'm not doing that) wanted have each cell able have different reveal color. yay! note, have create frame long (i.e., 500) swipe delete looks right.

here's code.

uilabel* label = [[uilabel alloc] initwithframe:cgrectmake(320, 0, 500, self.tableview.rowheight)]; label.backgroundcolor = [uicolor redcolor]; [cell.contentview addsubview:label];

ios uitableview swipe gestures

No comments:

Post a Comment