i'm trying move uiview relation user's touches.
here's have @ moment:
int oldx, oldy; bool dragging; - (void)touchesbegan:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [[event alltouches] anyobject]; cgpoint touchlocation = [touch locationinview:self.view]; if (cgrectcontainspoint(window.frame, touchlocation)) { dragging = yes; oldx = touchlocation.x; oldy = touchlocation.y; } } - (void)touchesmoved:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [[event alltouches] anyobject]; cgpoint touchlocation = [touch locationinview:self.view]; if (cgrectcontainspoint(window.frame, touchlocation) && dragging) { cgrect frame; frame.origin.x = (window.frame.origin.x + touchlocation.x - oldx); frame.origin.y = (window.frame.origin.y + touchlocation.y - oldy); window.frame = frame; } } - (void)touchesended:(nsset *)touches withevent:(uievent *)event { dragging = no; }
the view keeps flickering 1 location another, , don't know else do.
any appreciated.
modify touchesbegan , touchesmoved methods following.
float oldx, oldy; bool dragging;
the touchesbegan:withevent: method.
- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [[event alltouches] anyobject]; cgpoint touchlocation = [touch locationinview:self.view]; if (cgrectcontainspoint(window.frame, touchlocation)) { dragging = yes; oldx = touchlocation.x; oldy = touchlocation.y; } }
the touchesmoved:withevent: method.
- (void)touchesmoved:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [[event alltouches] anyobject]; cgpoint touchlocation = [touch locationinview:self.view]; if (dragging) { cgrect frame = window.frame; frame.origin.x = window.frame.origin.x + touchlocation.x - oldx; frame.origin.y = window.frame.origin.y + touchlocation.y - oldy; window.frame = frame; } }
the touchesended:withevent: method.
- (void)touchesended:(nsset *)touches withevent:(uievent *)event { dragging = no; }
Comments
Post a Comment