我在导航栏中添加一个UISegmentedControl。当纵向加载视图时,其框架看起来是正确的。但是当它旋转到横向时,UIBarButtonItem变大。如果再次旋转到肖像,它仍然保持较大的一个。如何在从纵向旋转到横向时更改UIBarButtonItem大小?
一些代码片段是在这里:
#define SEGMENT_WIDTH 100.0
#define SEGMENT_HEIGHT 32.0
CGRect segmentedControlRect = CGRectMake(0, 0, SEGMENT_WIDTH, SEGMENT_HEIGHT);
segmentedControl = [[UISegmentedControl alloc] initWithFrame:segmentedControlRect];
segmentedControl.momentary = NO;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBordered;
[segmentedControl addTarget:self action:@selector(tabButtonPressed:) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *segmentBarBtn = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
self.navigationItem.rightBarButtonItem = segmentBarBtn;
一些截图如下:
从纵向模式加载。
旋转到横向模式。
旋转回肖像模式。
任何建议将不胜感激。
使用autoresizingmask。请参考这里[UIView autoresizingmask](http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html) – Ashini 2013-05-10 04:49:47
@Ashini我试过autoresingmask,它的工作更糟糕:(。 – chancyWu 2013-05-10 05:17:45