Tuesday, 15 June 2010

ios - UIScrollView dragging overrules subview touchesBegan -



ios - UIScrollView dragging overrules subview touchesBegan -

all,

i have read lot of answers on stackoverflow , other sites , tried lot of possible solutions, none work.

i have uiscrollview (boardscrollview) subview backgroundimage (boardimage):

uiimage *image = [uiimage imagenamed:@"greyblue_numbered_15x15_900x900.png"]; self.boardimage = [[uiimageview alloc] initwithimage:image]; self.boardimage.frame = (cgrect){.origin=cgpointmake(0.0f, 0.0f), .size=image.size}; [self.boardscrollview addsubview:self.boardimage]; self.boardscrollview.contentsize = image.size;

i have implemented touchesbegan , touchesended drag&drop subview around on uiscrollview:

- (void)mytouchesended:(nsset *)touches withevent:(uievent *)event { cgpoint touchpointscreen = [[touches anyobject] locationinview:self.view]; cgpoint touchpointimage = [[touches anyobject] locationinview:self.boardimage]; if (touchpointscreen.x > self.boardscrollview.frame.origin.x && touchpointscreen.x < self.boardscrollview.frame.origin.x + self.boardscrollview.frame.size.width && touchpointscreen.y > self.boardscrollview.frame.origin.y && touchpointscreen.y < self.boardscrollview.frame.origin.y + self.boardscrollview.frame.size.height) { self.tmpdragobject.frame = cgrectmake(x,y,60,60); [self.boardimage addsubview:self.tmpdragobject]; } self.tmpdragobject = nil; }

the dragged subview dropped on imageview. can zoom in , out , subview repositioned.

this works perfect when scrollview zoomed out. when create drag-motion, subview dragged on scrollview.

but when zoom in on scrollview , seek drag dropped subview, touchesbegan overruled scrollviewwillbegindragging method, scrollview scrolled, subview not dragged.. somehow, dragging overrules touchesbegan method. because when touch, subview's touchesbegan method called. when create drag-motion, dragging-method uiscrollview called.

how can create both dragging in scrollview , touchesbegan in subview work when drag scrollview position of subview?

i have set

self.boardscrollview.cancancelcontenttouches = no; self.boardscrollview.userinteractionenabled = yes;

and on subview

self.exclusivetouch = yes; self.userinteractionenabled = yes;

what missing here?

ios objective-c uiscrollview touchesbegan

No comments:

Post a Comment