我在 Interface Builder 中为 3.5 英寸 iPhone 放置了一个文本字段和按钮。我以编程方式检查它是否是 iPhone 5,如果是文本字段和按钮。我在 View Controller 、文本字段和按钮上未选中“Autoresize Subviews”。我的代码在 viewDidLoad 中,如果它是 iPhone 5,它会点击行但不会移动文本字段或按钮。
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 568)
{
self.chatBox.frame = CGRectMake(20,509,201,30);
self.submitButton.frame = CGRectMake(227,504,73,39);
[self.view addSubview:self.chatBox];
[self.view addSubview:self.submitButton];
}
}
最佳答案
如果您使用自动布局,您的约束可能优先于上面的代码。没有自动布局,我使用了以下代码:
int adjustY=44;
CGPoint iPhone5center=CGPointMake(theButton.center.x,theButton.center.y+adjustY);
theButton.center=iPhone5center;
参见this question更多细节。我在 ScrollView 中使用自动布局时遇到问题。
关于iphone - 如何移动 Interface Builder 放置的文本字段和按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18753678/