Button stretching bug
===

I have these tabs that the user can tap on and expand.  As I decided was the correct way to avoid [this][1] problem, I am removing the tabs from the containing view and adding them to the window when they expand.  This seems to have resulted in a very strange bug: the texture for the normal state of the button is suddenly being stretched after the tab has been opened.

**Before**

![tabs all appear normal][2]

**After**

![first tab has been opened and closed, showing stretched texture][3]

I have done some relatively extensive logging, showing that before and after the open and close animations, the frame for the entire tab, and its enclosed button are exactly the same:

    2012-07-31 10:08:33.835 Project[1937:1c103] Button:{{0, 0}, {133, 25}}
    2012-07-31 10:08:33.836 Project[1937:1c103] Tab:{{0, 177.333}, {133, 25}}
    2012-07-31 10:08:34.340 Project[1937:1c103] Tab done:{{118, 777.5}, {133, 202.5}}
    2012-07-31 10:08:34.341 Project[1937:1c103] Button done:{{0, 0}, {133, 25}}

This issue **ONLY** occurs if I remove the tab from its containing view and add it to the window instead.  If I animate the tab within its containing view, the texture does not get messed up.

I'm at a total loss here.

Here is the code where I create the tab texture and button:


    tabImg = [[UIImage imageNamed:@"tab_stretchable"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 25, 15)];
    CGRect tabFrame = frame;
	tabFrame.origin.x = 0;
	tabFrame.origin.y = 0;
	tabButton = [[UIButton alloc] initWithFrame:tabFrame];
	[tabButton setBackgroundImage:tabImg forState:UIControlStateNormal];
	[tabButton addTarget:self action:@selector(tabPressed:) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:tabButton];

`frame` at this point is `{{0, 177.333}, {133, 25}}`


  [1]: http://stackoverflow.com/questions/11524440/how-to-prevent-a-uiview-from-consuming-user-input
  [2]: http://i.stack.imgur.com/IgTel.png
  [3]: http://i.stack.imgur.com/rMzJB.png