Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to commit a UIButton state change before starting other UIView animations?
    primarykey
    data
    text
    <p>I have a UIButton which fires a target action causing one view to transition to another on touchupinside.</p> <p>When this happens the I also change the button's state to selected but the (different) background image for the selected state doesn't actually draw until the UIView transition is complete (or sometimes it also seems to transition with the UIView transition.)</p> <p>How can I force the button to redraw the new background image before starting the view transition?</p> <p>The code that runs on UIControlEventTouchUpInside:</p> <pre><code>RhSubTab *activeTab; for(RhSubTab *tab in self.tabViews.copy) { tab.selected = NO; [self.view bringSubviewToFront:tab]; if(tab.tag == type) activeTab = tab; } [self.view bringSubviewToFront:activeTab]; [activeTab setSelected:YES]; UIView *oldView; UIView *newView; for(UIView *view in self.contentViews.copy) { if([self.view.subviews containsObject:view]) { oldView = view; } if(view.tag == type) { newView = view; } } if(!oldView) [self.view addSubview:newView]; else [UIView transitionFromView:oldView toView:newView duration:0.5 options:(UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseInOut) completion:nil]; </code></pre> <p>And the custom (RhSubTab) button class:</p> <pre><code>- (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if(self) { [self setBackgroundImage:[[UIImage imageNamed:@"SubContentTabBg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 9, 0, 40)] forState:UIControlStateNormal]; [self setBackgroundImage:[[UIImage imageNamed:@"SubContentTabBg-selected.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 9, 0, 40)] forState:UIControlStateSelected]; } return self; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload