ios - UITableView with UITableViewCell containing UIImageView -


okay, able scroll outside borders of uiimageviews, need able scroll on top of views. uiimageview contains pan gestures, pinch gestures, , unsure if causing error. paste cell code below:

func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     imageindex = indexpath.row      var cell : xpanddraggablecell = tableview.dequeuereusablecellwithidentifier("xpanddraggablecell", forindexpath: indexpath) as! xpanddraggablecell      cell.imgview.backgroundcolor = uicolor(red: 210, green: 211, blue: 213, alpha: 1.0)      if (horizontal) {         defaultx = defaultspacingx * imageindex; /* e.g 70 * 2 = 140 origin x. */     }else{         defaulty = defaultspacingy * imageindex; /* e.g 70 * 2 = 140 origin y. */     }      cell.imgview.frame = cgrect(x: cell.imgview.frame.origin.x, y: cell.imgview.frame.origin.y, width: 75.0, height: 75.0)     var cellwidth : cgfloat = cell.contentview.frame.width     var cellheight : cgfloat = cell.contentview.frame.height     cell.imgview.center = cgpoint(x: cell.contentview.frame.origin.x + (cellwidth / 2), y: cell.contentview.frame.origin.y + (cellheight / 2))     cell.imgview.image = uiimage(named: images[imageindex]) /*image provided*/     cell.imgview.contentmode = uiviewcontentmode.scaleaspectfit     cell.imgview.userinteractionenabled = true     cell.imgview.tag = imageindex      var addtoviewpangesture : uipangesturerecognizer = uipangesturerecognizer(target: self, action: selector("imageviewpanned:"))     cell.imgview.addgesturerecognizer(addtoviewpangesture)      var doubletapaddgesture : uitapgesturerecognizer = uitapgesturerecognizer(target: self, action: selector("celldoubletapped:"))     doubletapaddgesture.numberoftapsrequired = 2     cell.imgview.addgesturerecognizer(doubletapaddgesture)      cell.imgview.backgroundcolor = uicolor.clearcolor()     cell.imgview.layer.backgroundcolor = uicolor.clearcolor().cgcolor     cell.imgviewbtn.backgroundcolor = uicolor.clearcolor()     cell.backgroundcolor = uicolor(red: 210, green: 211, blue: 213, alpha: 1.0)      return cell }   class xpanddraggablecell : uitableviewcell{     @iboutlet var imgviewbtn: uibutton!     @iboutlet var imgview: uiimageview! } 

panning , scrolling "same" gesture.

the problem imageview's pan gesture recognizer recognizing gesture, , handling (instead of failing or passing touch through cell/tableview).

if expect able pan image in direction, can set pan gesture recognizer on tableviewcell, instead of image.

then check see if gesture's location within imageview. if so, begin gesture, pan gesture recognize it. when "pan" outside cell, gesture won't have been recognized pan gesture, , can recognized scroll.

- (bool)gesturerecognizershouldbegin:(uipangesturerecognizer *)gesturerecognizer {     cgpoint point = [gesturerecognizer locationinview:self.view];     cgrect frame = self.imageview.frame;     if (cgrectcontainspoint(frame, point))     {         return yes;     }      else     {         return no;     } } 

update:

based on edited question, have make gesture recognizer distinguish between dragging , scrolling. again, these similar gestures.

if touch image, move finger, how can ios know whether mean drag image, or scroll table? you're going have make educated guess:

  • if gesture left, it's drag. pan gesture recognizer should recognize gesture.

  • if gesture or down, it's scroll. pan gesture recognizer should fail gesture.

update 2:

here's code pan gesture recognizer determine whether touch should drag or scroll.

- (bool)gesturerecognizershouldbegin:(uipangesturerecognizer *)gesturerecognizer {     uiview *gestureview = [gesturerecognizer view];     cgpoint translation = [gesturerecognizer translationinview:[gestureview superview]];      // check horizontal gesture     if (fabsf(translation.x) > fabsf(translation.y))     {         return yes;     }      return no; } 

this stop pan gesture recognizer recognizing vertical gestures pans, , should scroll table, desire.

you'll find more information in similar questions.

having said this, other developers have bypassed pan-or-scroll tableview issue using long press gesture initiate drag. in case, it's clear pan gesture initiated drag, otherwise gesture scroll table (or swipe cell).

your app may not need swipe-to-delete it's not interfere, conflict with, or change behavior expected gestures users know.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -