0

I have a textfield and button that are placed by me in Interface Builder for the 3.5 inch iPhone. Im checking programmatically to see if it is an iPhone 5, if it is then the textfield and button. I have "Autoresize Subviews" unchecked on the View Controller, textfield, and button. The code I have is in the viewDidLoad, and if it is an iPhone 5, it hits the lines but doesn't move the textfield or button.

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];
    }
}
4

2 回答 2

1

如果您使用自动布局,您的约束可能优先于上面的代码。没有自动布局,我使用了这段代码:

    int adjustY=44;
    CGPoint iPhone5center=CGPointMake(theButton.center.x,theButton.center.y+adjustY);
    theButton.center=iPhone5center; 

有关更多详细信息,请参阅此问题。我在滚动视图中使用自动布局时遇到问题。

于 2013-09-12T01:41:14.843 回答
0

您在这里遇到的问题是框架被自动布局覆盖。在使用自动布局调整视图上的框架之前,添加以下代码行:

[self setTranslatesAutoresizingMaskIntoConstraints:YES];

这应该将您设置的任何框架转换为新的约束并更新它们。如果您不想将它们转换为约束,显然只需将“NO”传递给此消息即可实现此目的。

于 2013-09-12T02:29:19.030 回答