Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8085111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:00:38+00:00 2026-06-05T18:00:38+00:00

I have a UIButton which fires a target action causing one view to transition

  • 0

I have a UIButton which fires a target action causing one view to transition to another on touchupinside.

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.)

How can I force the button to redraw the new background image before starting the view transition?

The code that runs on UIControlEventTouchUpInside:

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];

And the custom (RhSubTab) button class:

- (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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:00:39+00:00Added an answer on June 5, 2026 at 6:00 pm

    Try breaking out the second part of your method (after setting the button to the selected state) into a second method.

    Then use performSelector:withObject:afterDelay: to call that second method

    So your method might look like this:

    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];
    
    [self performSelector: @selector(doTransition) withObject: nil afterDelay: 0];
    

    And your second method might look like this:

    - (void) doTransition;
    {
      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];
    }
    

    Even with a delay value of 0, the performSelector:withObject:afterDelay: returns immediately, and doesn’t trigger the specified method until the next path through the event loop, after checking for user events, processing screen updates, etc.

    If you want the transition to wait until the button change is complete, you might want to add a small non-zero delay value.

    The method performSelector:withObject:afterDelay: will let you pass 0 or 1 objects as parameters. At a glance, it did not look like the second half of your transition method needed any parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIButton which I've added in IB, however the view behind this
I have a view controller, MainViewController in which I have a UIButton as an
I have a UIButton which calls a method from another UIViewController , that method
I have created a small UIView which contains two UIButton s. The view responds
I want to switch to another viewController. I have an UIButton on my view,
I have a background UI Image which is shown whenever i touch a UIButton:
I'm trying to create a UIButton programmatically. I have a button called addCash (which
I have a detail view that includes three UIButtons, each of which pushes a
I have a UIButton that performs an Action when it is touched down. I
I have a UIButton which i add programmatically. No problems here, it stetches as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.