【问题标题】:how to change the UIBarButtonItem size when rotate from the portrait to landscape?从纵向旋转到横向时如何更改 UIBarButtonItem 的大小?
【发布时间】:2013-05-10 04:45:46
【问题描述】:

我向导航栏添加了一个 UISegmentedControl。当视图以纵向加载时,它的框架看起来是正确的。但是当它旋转到横向时, UIBarButtonItem 会变大。如果再次旋转到纵向,它仍然是较大的。

一些代码sn-p在这里:

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

部分截图如下:

  1. 从纵向模式加载。

  2. 旋转到横向模式。

  3. 旋转回纵向模式。

任何建议将不胜感激。

【问题讨论】:

  • 使用自动调整掩码。参考这里UIView autoresizingmask
  • @Ashini 我试过 autoresingmask,效果更差:(.

标签: iphone ios uiview uinavigationcontroller uibarbuttonitem


【解决方案1】:

不要在导航栏中使用边框样式!使用UISegmentedControlStyleBar。这就是它的用途。

另外,不要设置分段控件的大小(框架)。只需使用 alloc-init 创建它,然后允许它使用自己的内在大小规则 (sizeToFit)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-03
    • 2023-03-05
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 2015-10-25
    相关资源
    最近更新 更多