【发布时间】:2014-10-13 11:29:31
【问题描述】:
当用户触摸 webview 中的文本字段时,我试图移动 UIView,因为键盘会覆盖 webview 并且用户将无法输入文本,我的代码工作得很好!在 iOS 7 上!!!但是 iOS 8 视图向上移动,但是当用户选择另一个文本字段(在 webview 中)时,UIView 向下移动到初始位置!!! .这是我的代码:
/* _contactForm = UIWebView
_contactView = UIView */
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardDidShow: (NSNotification *) notif {
[[[_contactForm subviews] lastObject] setScrollEnabled:YES];
if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPad) {
[UIView animateWithDuration:.20
delay:0
options:UIViewAnimationOptionCurveLinear animations:^
{
[_contentView setFrame:CGRectMake(0, 37 , _contentView.frame.size.width, _contentView.frame.size.height)];
} completion:nil];
}
}
- (void)keyboardDidHide: (NSNotification *) notif{
[[[_contactForm subviews] lastObject] setScrollEnabled:NO];
[UIView animateWithDuration:.20
delay:0
options:UIViewAnimationOptionCurveLinear animations:^
{
[_contentView setFrame:CGRectMake(0, 176 , _contentView.frame.size.width, _contentView.frame.size.height)];
}completion:nil];
}
}
我也试过UIKeyboardDidHideNotification和UIKeyboardDidShowNotification,但没有成功!
WebView 从 bundle 加载一个 HTML 文件,这是文本字段的代码:
<form action="http://someurl.net/mail/mail.cshtml" method="post" onsubmit="return validate();">
<input class="textInput" type="text" name="name" placeholder="NAME"/>
<div class="clearfix"></div>
<input class="textInput" type="email" name="email" placeholder="EMAIL"/>
<div class="clearfix"></div>
<input class="textInput" type="text" name="phone" placeholder="PHONE"/>
<div class="clearfix"></div>
<textarea name="msg" cols="19" rows="3" placeholder="MESSAGE"></textarea>
<div class="clearfix"></div>
<input type="submit" class="submit" value="SEND"/>
</form>
【问题讨论】:
-
你能给我网址吗。
-
@KiritModi 请检查编辑后的答案
-
能否请您尝试在隐藏和显示方法上设置断点。我想知道当用户从一个字段点击到另一个字段时两者是否都会被调用。
标签: ios objective-c iphone uiview uiwebview