ios - How to properly animate UIButton between states? -


i wanted make slow dissolve animation between default , highlighted uibutton state. pressing button performs segue, , takes viewcontroller. have managed animation writing subclass of uibutton single method:

- (void) touchesbegan:(nsset *)touches withevent:(uievent *)event {     [uiview transitionwithview:self                       duration:0.15                        options:uiviewanimationoptiontransitioncrossdissolve                     animations:^{ self.highlighted = yes; }                     completion:nil];      [super touchesbegan:touches withevent:event]; } 

and writing in prepareforsegue method of main viewcontroller:

if ([sender iskindofclass:[uibutton class]]) {         uibutton* button = (uibutton*)sender;         [uiview transitionwithview:button                           duration:0.15                            options:uiviewanimationoptiontransitioncrossdissolve                         animations:^{ button.highlighted = no; }                         completion:nil];     } 

this works well, dividing execution of single animation 2 files not seem best idea. there better way of doing this?

p.s. using second part of code in touchesended not work :(

instead of using touchesbegan , touchesended can try perform highlighting in control events of button.

in uibutton subclass:

[self addtarget:self action:@selector(ontouchdown) forcontrolevents:(uicontroleventtouchdown | uicontroleventtouchdragenter)]; [self addtarget:self action:@selector(ontouchup) forcontrolevents:(uicontroleventtouchupinside | uicontroleventtouchupoutside | uicontroleventtouchdragexit | uicontroleventtouchcancel)]; 

the event methods:

-(void)ontouchdown {     //perform dissolve animation here }  -(void)ontouchup {     //remove dissolve animation here } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -