IOS draggable objects not saving position -
i have view contains number of buttons , single text field. users can drag buttons around, , when finished, interact text field. dragging buttons using uipangesturerecognizer seems work, once user interacts text field, of buttons snap original positions.
i after dragging button, button's new position saved, or @ least doesn't revert original position when interacting other objects in same view.
i have attached code gesture recognizer:
- (ibaction)handlepan:(uipangesturerecognizer *)recognizer { cgpoint translation = [recognizer translationinview:self.view]; recognizer.view.center = cgpointmake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y); //[recognizer settranslation:cgpointmake(0, 0) inview:self.view]; uibutton *button = (uibutton*)recognizer.view; if (recognizer.state == uigesturerecognizerstateended) { button.center = recognizer.view.center; [recognizer settranslation:cgpointmake(0, 0) inview:self.view]; } }
thank help.
make sure buttons aren't handled autolayout. if working in ib, make sure remove constraints buttons. or, if want keep using autolayout, update constraints on button rather updating it's center position. can removing old constraints , setting new constraint positioning button want it.
short version
remove constraints on button if want move it
Comments
Post a Comment