views:

29

answers:

2

I have a custom UISegmentedControl that I placed using IB into a Navigation bar much like it is done in the iTunes App. When the device is rotated in landscape mode, I want to repopulate the segmented control to make use of the more space I have there.

I do:

CGFloat controlWidth = self.frame.size.width;

where self is the custom UISegmentedControl but that always returns 310 as the width.

Now in both code I also set the following resizing mask:

self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

which actually makes the segmented control expand properly.

Any suggestions?

A: 

Here are two things that may help:

  1. Something about the "top-level" view/container is not "rotated" - thus it's frame stays the same - though it's subviews are rotated and thus have new frame sizes.

  2. Look at the bounds, not the frame.

I think either one (or both) are pertinent to you.

Brad
A: 

ok I figured it out. It was neither the top-level view/container or the bounds issues. I was just checking at the wrong time. I had placed the call to check the width inside shouldAutorotateToInterfaceOrientation: and of course that only gets called BEFORE the rotation. Duh. I used didRotateFromInterfaceOrientation and that solved it.

Thanks for the suggestions because after trying them out, I noticed that my method was getting called at different times and eventually it worked so I figured it was a timing thing.

pfs