ios - Animate to a storyboard state / position -


i've got view controller in storyboard has bunch of images, labels , buttons correctly positioned how view supposed after initial animations.

is there simple way save original position of each , every element (that position they're in on storyboard) on init it's possible take elements, move them out of view , animate them storyboard layout / positions?

yes can done saving view's constraints in array, removing them, , replacing them new off-screen constraints (the example have work if want move in self.view -- if want move of views, need loop through of self.view's constraints, , add pertain views want move array). when want move views storyboard defined positions, remove current ones, re-add saved ones, , call layoutifneeded in animation block.

@interface viewcontroller () @property (weak, nonatomic) iboutlet uibutton *bottombutton; @property (weak, nonatomic) iboutlet uibutton *topbutton; @property (weak, nonatomic) iboutlet uibutton *middlebutton; @property (strong,nonatomic) nsarray *finalconstraints; @end  @implementation viewcontroller  - (void)viewdidload {     [super viewdidload];     nsdictionary *viewsdict = nsdictionaryofvariablebindings(_bottombutton,_topbutton,_middlebutton);     self.finalconstraints = self.view.constraints; // save storyboard constraints     [self.view removeconstraints:self.view.constraints]; // remove storyboard constraints     [self.view addconstraints:[nslayoutconstraint constraintswithvisualformat:@"[_topbutton]-(-30)-|" options:0 metrics:nil views:viewsdict]];     [self.view addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:[_topbutton]-(-30)-|" options:0 metrics:nil views:viewsdict]];      [self.view addconstraints:[nslayoutconstraint constraintswithvisualformat:@"[_middlebutton]-(-30)-|" options:0 metrics:nil views:viewsdict]];     [self.view addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:[_middlebutton]-(-30)-|" options:0 metrics:nil views:viewsdict]];      [self.view addconstraints:[nslayoutconstraint constraintswithvisualformat:@"[_bottombutton]-(-30)-|" options:0 metrics:nil views:viewsdict]];     [self.view addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:[_bottombutton]-(-30)-|" options:0 metrics:nil views:viewsdict]];      [self performselector:@selector(movetofinalpositions) withobject:nil afterdelay:2]; }  - (void)movetofinalpositions {     [self.view removeconstraints:self.view.constraints];     [self.view addconstraints:self.finalconstraints];     [uiview animatewithduration:2 animations:^{         [self.view layoutifneeded];     }]; } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -