【发布时间】:2015-02-04 09:59:57
【问题描述】:
在我的应用中,我有这个登录屏幕:
在第一个测试字段上方我有一张图片,Interface Builder 中的配置如下:
现在,当我点击 UITextField 时,它们应该向上移动,否则在 iPhone 4/4s 中,该字段将被键盘覆盖。 现在我正在使用以下代码:
-(void)textFieldDidBeginEditing:(UITextField *)textField {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.35f];
CGRect frameView = self.view.frame;
CGRect frameImage = self.imageViewLogo.frame;
CGRect frameTextFieldUsername = self.textFieldUsername.frame;
CGRect frameTextFieldPassword = self.textFieldPassword.frame;
CGRect frameButtonLogin = self.buttonLogin.frame;
frameView.origin.y = -100;
frameImage.origin.y = -100;
frameTextFieldUsername.origin.y = -100;
frameTextFieldPassword.origin.y = -100;
frameButtonLogin.origin.y = -100;
[self.view setFrame:frameView];
[self.imageViewLogo setFrame:frameImage];
[self.textFieldUsername setFrame:frameTextFieldUsername];
[self.textFieldPassword setFrame:frameTextFieldPassword];
[self.buttonLogin setFrame:frameButtonLogin];
[UIView commitAnimations];
}
当我尝试在模拟器或真实设备上运行应用程序时,视图向上滚动 100,但图像、文本字段和按钮不向上滚动...我认为问题取决于约束,你能帮我解决这个问题吗? 谢谢
【问题讨论】:
-
您必须添加 UIScrollView 并获取两个文本字段,然后下载 github.com/michaeltyson/TPKeyboardAvoiding。将 UIScrollView 的主类带到 TPKeyboardAvoidingScrollView。
-
不需要使用scrollView等第三方类。检查我的答案。
标签: ios objective-c iphone