iphone - iOS translation and scale animation -


i'm working on uibutton animation where:

the uibutton set in bottom center of screen , scaled small size

_menubtn.transform = cgaffinetransformmakescale(0.1f, 0.1f); 

when app starts should moving bottom left side of screen scales or grow original size.

- (void)viewdidload {     [super viewdidload];      _menubtn.frame = cgrectmake(160, 513, 30, 30);      _menubtn.superview.frame = cgrectmake(160, 513, 30, 30);      _menubtn.transform = cgaffinetransformmakescale(0.1f, 0.1f);     nslog(@"_menubtn: %@ ; _menubtn.superview: %@", _menubtn, _menubtn.superview);     [uiview beginanimations:nil context:nil];     [uiview setanimationdelegate:self];     [uiview setanimationduration:5];     [uiview setanimationcurve:uiviewanimationcurveeaseout];     cgaffinetransform scaletrans  = cgaffinetransformmakescale(1.0f, 1.0f);     cgaffinetransform lefttorighttrans  = cgaffinetransformmaketranslation(-200.0f,0.0f);     _menubtn.transform = cgaffinetransformconcat(scaletrans, lefttorighttrans);     [uiview commitanimations];  } 

problem

when animation starts button starts moving bottom right side of screen , not in bottom center , should be. ?

log result

nslog(@"%@", _mybtn);  2013-08-14 09:22:38.913 gjcoolnavi[339:c07] <uibutton: 0x813ea30; frame = (0 0; 0 0); opaque = no; autoresize = tm+bm; layer = <calayer: 0x813eaf0>> 

thats before doing animation...and result after animation is:

2013-08-14 09:30:25.719 gjcoolnavi[612:c07] <uibutton: 0x71206d0; frame = (160 294; 0 0); opaque = no; autoresize = tm+bm; animations = { transform=<cabasicanimation: 0x7536a80>; position=<cabasicanimation: 0x7537dd0>; }; layer = <calayer: 0x7120790>> 

why don't this...

_menubtn.transform = cgaffinetransformmakescale(0.1, 0.1);  [uiview animatewithduration:5.0 options:uiviewanimationoptioncurveeaseout animations:^(){     _menubtn.transform = cgaffinetransformmakescale(1.0, 1.0);     _menubtn.center = self.view.center; } completion:nil]; 

i'd avoid moving stuff using transform. change frame instead.

edit

- (void)viewdidload {     [super viewdidload]; }  - (void)viewdidappear:(bool)animated {     [super viewdidappear:animated];      // convenience i'm pulling these values out in variables.     float buttonwidth = _menubtn.frame.size.width;     float buttonheight = _menubtn.frame.size.height;     float viewwidth = self.view.frame.size.width;     float viewheight = self.view.frame.size.height;      // set button frame bottom center     // note shouldn't have interface builder should place there.     // place button in horizontal center , 20 points bottom of view.     _menubtn.frame = cgrectmake((viewwidth - buttonwidth) * 0.5, viewheight - buttonheight - 20, buttonwidth, buttonheight);      // scale button down before animation...     _menubtn.transform = cgaffinetransformmakescale(0.1, 0.1);      // animate view...     [uiview animatewithduration:5.0                           delay:0.0                         options:uiviewanimationoptioncurveeaseout                      animations:^{                          _menubtn.transform = cgaffinetransformidentity;                          _menubtn.frame = cgrectmake(viewwidth - buttonwidth - 20, viewheight - buttonheight - 20, buttonwidth, buttonheight);                      }                      completion:nil]; } 

try , let me know happens.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -