Sliding deletion is already supported in the current iOS version, but it is complicated to say that there are multiple features after sliding, not deleting the function, then you have to write it yourself, I'm right ...
In fact, on the slide to delete, in the previous project also encountered, at that time, iOS does not support sliding delete, so only to see their own, at that time I was in the Code4app up and down the case modified, so this function has been done before, But the sad thing is that the Android programmer over the internet after the case to modify the project needs effect, fixed this function was finally castrated project experience .....
Time flies, the company has changed a number of hehe ...
The current company this project is related to the cell sliding function operation, although the current iOS has been sliding to delete, but he does not fully meet the current project requirements, so I have to see himself, this time I did not plan to go to the online case, because the project time is not so urgent, so I wrote Oh ... (Enter the topic below)
Today I give you to explain the focus is I realize the idea of this function, I want to let everyone understand is my idea of realization, when I use this idea to achieve this function, and then think about the last time to do this function, from the online case is not worth my nostalgia ....
First map my company to achieve the following functions:
Understand the people know, a look at this thing with iOS with the sliding exercise is not good hehe
The first control to display the content is UITableView
Three cell is actually a cell, the three different states, if you do not know, you do not continue to see the following ...
The first is selected: The address that the user will submit
The second one is selected:
The third one is the effect of our cell sliding, and when this part of the function slides, we need to hide the small circle button
Here's what I'm going to focus on.
Each control shown in the cell is add to a scrollview and then add ScrollView to the cell
The section width of the cell slide show needs to be added to ScrollView's contentsize. Here's the code.
Uiscrollview *contentview=[[uiscrollview alloc]initwithframe:cgrectmake (0, 0, Device_width, 79)];
[Contentview Setcontentsize:cgsizemake (device_width+70,79)];
[Contentview Setbackgroundcolor:[uicolor Whitecolor];
[Contentview Setshowshorizontalscrollindicator:no];
Contentview.scrollenabled=yes;
First introduce the agent of ScrollView to <UIScrollViewDelegate>
Then you need to implement the following proxy:
ScrollView Agent-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{_recordcurrentoffsetx= Scrollview.contentoffset.x; }//drag start and the end of the leg, both agents must be added, otherwise cannot execute enddragging-(void) scrollviewwillbegindragging: (Uiscrollview *) scrollview{}-(void) Scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate{if (!decelerate) {Nsarr Ay *backgroundviewchilrendarray=scrollview.subviews; if (_recordcurrentoffsetx<70) {[ScrollView setcontentoffset:cgpointmake (0, Scrollview.contentoffset.y) anim Ated:yes]; for (int i=0;i<backgroundviewchilrendarray.count; i++) {if ([[Backgroundviewchilrendarray Objectatindex : i] Iskindofclass:[uibutton class]) {UIButton *button=[backgroundviewchilrendarray objectatindex:i]; if (button.tag==11010) {button.hidden=no; Break } }}} else {for (int i=0;i<backgroundviewc Hilrendarray.count; i++) {if ([[[Backgroundviewchilrendarray objectatindex:i] Iskindofclass:[uibutton class]) { UIButton *button=[backgroundviewchilrendarray OBJECTATINDEX:I]; if (button.tag==11010) {button.hidden=yes; Break }}}}}}-(void) scrollviewwillbegindecelerating: (Uiscrollview *) Scrollvi ew{}-(void) scrollviewdidenddecelerating: (Uiscrollview *) scrollview{Nsarray *backgroundviewchilrendarray= Scrollview.subviews; if (_recordcurrentoffsetx<70) {[ScrollView setcontentoffset:cgpointmake (0, Scrollview.contentoffset.y) animated : YES]; for (int i=0;i<backgroundviewchilrendarray.count; i++) {if ([[BackgroundviewChilrendarray Objectatindex:i] Iskindofclass:[uibutton class]) {UIButton *button=[backgroundviewchilrenda Rray OBJECTATINDEX:I]; if (button.tag==11010) {button.hidden=no; Break }}}} else {for (int i=0;i<backgroundviewchilrendarray.count; i++) { if ([[[Backgroundviewchilrendarray objectatindex:i] Iskindofclass:[uibutton class]) {UIButton *butto N=[backgroundviewchilrendarray OBJECTATINDEX:I]; if (button.tag==11010) {button.hidden=yes; Break } } } } }
_recordcurrentoffsetx: is a cgfloat variable field that records the x-coordinate of an offset
if (_recordcurrentoffsetx<70) {}
The above sentence is to judge the current ScrollView offset, the above code of the <70---70 is our cell expansion of the part of the storage of the slide-delete function.
If two is less than 70, we set the offset to 0 and do not show the sliding delete section.
At first I used the gesture to do this function,cell add is UIView, not ScrollView, and then add the corresponding gesture to UIView, the logic is relatively complex, made to have a bug, is when I pull down this uitableview refresh (not at all, but to perform contentview binding gestures), if I set the width of the border to 0, then it will not be executed at all, why I think I do not say you know. And I used to write the case, the case, although solved, I use the confusion of gestures, but the experience is completely bad, and the cell add a lot of layers, realize the code of many .... My point today is: When the project involves writing the cell's sliding function, you can choose me this way, just add a uiscrollview in the UITableView, then slide the extra width, Add to the Uiscrollview of the contensize, and then adjust a few agents are completely finished hehe ..... (This cell slider method I don't seem to have seen anyone on the internet, mostly using gestures.)
Objective-c Custom Slide (original)