Reputation: 40030
I have a problem with sendSubviewToBack
and insertSubview:belowSubview:
methods. Simply, I have a button which I'm inserting below another view _centerView
. I want the button to stay below the _centerView
.
The problem I'm facing is that when I insert a button below the _centerView
I see a flicker (just for a short moment) over the _centerView
. I tried both sendSubviewToBack:
and insertSubview:belowSubview:
- same effect.
Do you have any ideas what things may be wrong? Am I missing something? Here is my code:
UIButton* itemButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[itemButton setFrame:CGRectMake(0, 0, 40, 40)];
[itemButton setCenter:_centerView.center];
[parentView bringSubviewToFront:_centerView];
[parentView insertSubview:itemButton belowSubview:_centerView];
Upvotes: 1
Views: 1974
Reputation: 91
I recently came across this same issue, but passing this option to the animation code fixed it. Hopefully this is helpful to you too. I wouldn't have come up with my solution without your comment though, so thanks for that :)
UIViewAnimationOptionShowHideTransitionViews
Upvotes: 2
Reputation: 40030
OK, so after a while it turned out that this is the fault of the window I animated the same time I added the button. I don't know why but the fade in animation of the window was causing this problem. I switched of the animations of my UIWindow and now it works. Thanks for help!
Upvotes: 0
Reputation: 1176
I'm not sure what the internal structure behind insertSubview
is, but if you want to get rid of the flicker, the easiest way would be to hide the view before inserting it and show it again afterwards.
[itemButton setHidden:YES];
[parentView insertSubview:itemButton belowSubview:_centerView];
[itemButton setHidden:NO];
Not the most elegant solution, but it should get the job done.
Upvotes: 0