gpt4 book ai didi

ios - Objective C iOS UISegmentedControl 意外改变位置

转载 作者:行者123 更新时间:2023-11-28 22:12:30 25 4
gpt4 key购买 nike

我有一个 UISegmented 控件,只要 View 进入横向 View ,我就需要更改它的位置。我的代码有效,但出于某种非常奇怪的原因,每当我尝试选择分段控件时,它都会移回屏幕外的纵向位置。这不会发生在我使用相同方法移动它们的按钮上。

代码:

// handle landscape view
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];

CGSize size = [UIScreen mainScreen].bounds.size;
UIApplication *app = [UIApplication sharedApplication];
UIInterfaceOrientation orientation = [app statusBarOrientation];

if (UIInterfaceOrientationIsLandscape(orientation)) size = CGSizeMake(size.height, size.width);
if (!app.statusBarHidden) size.height -= MIN(app.statusBarFrame.size.width, app.statusBarFrame.size.height);

if (UIInterfaceOrientationIsLandscape(orientation))
{
// CGRects of segmented controls
CGRect modeFrame = [self offAutoHeatCool].frame;
CGRect fanModeFrame = [self fanMode].frame;

modeFrame.origin.y = someRelativeInt;
fanModeFrame.origin.y = someRelativeInt;

modeFrame.origin.x = someRelativeInt;
fanModeFrame.origin.x = someRelativeInt;

[[self modeLabel] setFrame:modeLabelFrame];
[[self offAutoHeatCool] setFrame:modeFrame];
}
}

编辑:

请记住,我需要将某些 UI 元素从彼此上方或下方移动到相对 UI 元素的一侧。我不确定您是否可以使用自动布局来执行此操作,无论如何我更愿意以编程方式执行此操作。

最佳答案

处理 View 围绕调整大小(或方向改变)父 View 移动的正确方法是使用自动布局。一旦您开始使用它,它将为您省去很多麻烦。看看这里的文档:

https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/Introduction/Introduction.html

希望这对您有所帮助!

关于ios - Objective C iOS UISegmentedControl 意外改变位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22541575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com