Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 旋转到横向后自定义UISegmentedControl的高度问题 问题_Iphone_Ios_Uisegmentedcontrol - Fatal编程技术网

Iphone 旋转到横向后自定义UISegmentedControl的高度问题 问题

Iphone 旋转到横向后自定义UISegmentedControl的高度问题 问题,iphone,ios,uisegmentedcontrol,Iphone,Ios,Uisegmentedcontrol,我已经为一个iOS应用程序创建了一个自定义的UISegmentedControl组件,放置在导航栏上,带有两个段。正如人们所期望的,当手机旋转到横向时,组件的高度略短 然而,问题是在旋转到横向后,分段控件即使旋转回纵向后仍保持其短高度。我感谢你的帮助 以下是(简化的)代码,它位于initWithCoder:方法中: UIImage *bg = [[UIImage imageNamed:@"button-bg"] resizableImageWithCapInsets:UIEdgeInsetsMa

我已经为一个iOS应用程序创建了一个自定义的
UISegmentedControl
组件,放置在导航栏上,带有两个段。正如人们所期望的,当手机旋转到横向时,组件的高度略短

然而,问题是在旋转到横向后,分段控件即使旋转回纵向后仍保持其短高度。我感谢你的帮助

以下是(简化的)代码,它位于
initWithCoder:
方法中:

UIImage *bg = [[UIImage imageNamed:@"button-bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(7, 7, 7, 7)];
UIImage *bgH = [[UIImage imageNamed:@"button-bg-h"] resizableImageWithCapInsets:UIEdgeInsetsMake(7, 7, 7, 7)];

[self setBackgroundImage:bg forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[self setBackgroundImage:bg forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
[self setBackgroundImage:bgH forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[self setBackgroundImage:bgH forState:UIControlStateSelected barMetrics:UIBarMetricsLandscapePhone];
self.segmentedControlPortraitOrientationFrame = self.segmentControl.frame;
============================

临时解决办法 在我找到更好的解决方案之前,这里是我的临时解决方案:

在视图控制器中,我有一个名为
segmentControl
的插座,它链接到所讨论的
UISegmentedControl
。我还创建了一个属性,如下所示:

@property CGRect segmentedControlPortraitOrientationFrame;
viewDidLoad
方法中:

UIImage *bg = [[UIImage imageNamed:@"button-bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(7, 7, 7, 7)];
UIImage *bgH = [[UIImage imageNamed:@"button-bg-h"] resizableImageWithCapInsets:UIEdgeInsetsMake(7, 7, 7, 7)];

[self setBackgroundImage:bg forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[self setBackgroundImage:bg forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
[self setBackgroundImage:bgH forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[self setBackgroundImage:bgH forState:UIControlStateSelected barMetrics:UIBarMetricsLandscapePhone];
self.segmentedControlPortraitOrientationFrame = self.segmentControl.frame;
然后使用以下实现重写
didRotateFromInterfaceOrientation:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    [super didRotateFromInterfaceOrientation:interfaceOrientation];
    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
        self.segmentControl.frame = self.segmentedControlPortraitOrientationFrame;
}

解决方案假设应用程序总是首先以纵向加载,我认为这是正确的,只要应用程序支持纵向。如果我错了,请纠正我。

您是否使用了任何约束/弹簧和支柱/自动重新定位工具?另外,在旋转回纵向时,是否调用旋转方法?不使用自动布局,也不使用调整大小遮罩
UISegmentedControl
无论如何都不允许在其高度上自动调整遮罩的大小,至少看起来不允许通过IB。。。您指的是哪种旋转方法?我怎么查?