ios - UIButton animation not working properly -
see commented code below. why uibutton act differently uiview?
//button creation uibutton *mybtn = [uibutton buttonwithtype:uibuttontypecustom]; [mybtn setimage:[uiimage imagenamed:@"someimage"] forstate:uicontrolstatenormal]; self.mybutton = mybtn; ... ///in button target method: uiview* test = [[uiview alloc] initwithframe:self.mybutton.frame]; test.backgroundcolor = [uicolor redcolor]; [buttoncontainer addsubview:test]; [uiview beginanimations:@"someanimation" context:nil]; [uiview setanimationduration:5]; [uiview setanimationdelegate:self]; self.mybutton.frame = cgrectmake(100,100,200,200); //the position animates smoothly, size snaps 200,200 //test.frame = cgrectmake(100,100,200,200); //this works perfectly. position , size both animate smoothly on 5 seconds. [uiview commitanimations];
@implementation uibutton(fixresizeanimation) - (void)setframe:(cgrect)_frame { [super setframe:_frame]; for(uiview* v in self.subviews) { if([v iskindofclass:[uiimageview class]]) { [v setframe:_frame]; } } } @end
please try!
Comments
Post a Comment