scrollView.setContentOffset不会滚动视图,根本就不会滚动视图
我一直在关注this和一堆其他教程/博客等试图让我的视图滚动时,用户点击“返回”,并在UITextField结束正在被键盘覆盖,但没有任何实际工作。scrollView.setContentOffset不会滚动视图,根本就不会滚动视图
我想知道我必须做什么或失踪是造成这种情况?
基本上是:
- 用户想要做一些应用程序:添加信用卡
- 显示,包含了所有的CC领域
- 的UITextFields的1/2是由覆盖一个UIView键盘
- 当用户到达那里时滚动视图。
什么都没有发生。检测'被键盘覆盖'的代码正在被执行,但是:[self.scrollView setContentOffset:scrollPoint animated:YES]
根本没有任何效果。
想法?
显示截图:
代码:相同的链接教程。那里没有新东西。
试试这个,
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[UIView animateWithDuration:0.25 animations:^{
[yourTextField setFrame:CGRectMake(yourTextField.frame.origin.x, yourTextField.frame.origin.y-keyboardHeight, yourTextField.frame.size.width, yourTextField.frame.size.height)];
}];
}
和
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[UIView animateWithDuration:0.25 animations:^{
[yourTextField setFrame:CGRectMake(yourTextField.frame.origin.x, yourTextField.frame.origin.y+keyboardHeight, yourTextField.frame.size.width, yourTextField.frame.size.height)];
}];
}
我做些什么来避免文本框被覆盖的键盘当用户触摸它的文本框动画在屏幕的顶部开始通过键盘输入内容并在完成后将其回放。我认为它更优雅。也许这可能是你的替代解决方案。我做它用不同的号码不同screensizes ......你可能需要调整它,当然......
所以听的文本字段代表和
- (void)textFieldDidBeginEditing:(UITextField *)textField {
你做
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480){
({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = -196; [self.view setFrame:frame]; [UIView commitAnimations];});
}
if(result.height == 568){
({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = -196; [self.view setFrame:frame]; [UIView commitAnimations];});
}
if(result.height == 667){
({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = -238; [self.view setFrame:frame]; [UIView commitAnimations];});
}
if(result.height == 736){
({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = -251; [self.view setFrame:frame]; [UIView commitAnimations];});
}
和
- (void)textFieldDidEndEditing:(UITextField *)textField {
你只是BA动画ck
({[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.35f]; CGRect frame = self.view.frame; frame.origin.y = 0; [self.view setFrame:frame]; [UIView commitAnimations];});
您是否检查过contentSize属性?
要使滚动视图可滚动,内容必须大于显示区域(通常是滚动视图的边界)。
您可以通过默认
除了明确设置contentSize财产是CGSizeZero,设置contentInset属性来调整显示区域的大小,实现这一目标(在这种情况下,你可以设置底值等于键盘高度)当键盘弹出时
仅适用于iOS 8。 iOS 7没有效果。谢谢。 – cbrulak
你能显示/发布你的代码吗? –
您是否在添加内容后设置了滚动视图的contentSize? –