iPhone/iPad键盘弹出遮挡要编辑内容问题
2011-04-02 16:17
453 查看
当系统收到显示键盘的请求时,就从屏幕的底部滑出键盘,并将它放在应用程序内容的上方。由于键盘位于内容的上面,所以有可能遮掩住用户希望编辑的文本对象,只能盲操^_^
如何解决可以参考iPhone应用程序编程指南 http://www.apple.com.cn/developer/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TextandWeb/TextandWeb.html#//apple_ref/doc/uid/TP40007072-CH20-SW16
大体思路是:暂时调整一或多个视图的尺寸和位置,从而使文本对象可见。管理带有键盘的文本对象的最简单方法是将它们嵌入到一个UIScrollView(或其子类,如UITableView)对象。当键盘被显示出来时,需要做的只是调整滚动视图的尺寸,并将目标文本对象滚动到合适的位置。为此,在UIKeyboardDidShowNotification通告的处理代码中需要进行如下操作:
1. 取得键盘的尺寸。
2. 将滚动视图的高度减去键盘的高度。
3. 将目标文本框滚动到视图中。
但有时会碰到要编辑字段不在UIScrollView中的情况,比如烟草项目中点击靠近底部的烟草信息,弹出的popover可能会被弹出的键盘遮盖,这时通过简单的调整popover箭头方向即可实现弹出窗口随弹出键盘滑动的效果,当iPad竖着放置时点击列表中靠上部的行,箭头朝上;点击靠下部的行,箭头朝下;iPad横向放置时箭头朝右,效果如图所示:
[align=center]iPad竖着放置时点击列表中靠上部的行,箭头朝上[/align]
[align=center] [/align]
[align=center]点击靠下部的行,箭头朝下[/align]
[align=center]竖向放置弹出键盘效果[/align]
[align=center] [/align]
[align=center]横向放置时箭头朝右[/align]
[align=center]横向放置弹出键盘效果[/align]
代码如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
OrderNumViewController *orderNumViewController = [[OrderNumViewController alloc] init];
orderNumViewController.containerViewController = self;
if (orderNumPopover == nil) {
orderNumPopover = [[UIPopoverController alloc] initWithContentViewController:orderNumViewController];
}else {
orderNumPopover.contentViewController = orderNumViewController;
}
OrderOnlineCell *cell = (OrderOnlineCell *)[tableView cellForRowAtIndexPath:indexPath];
NSArray *indexArray = [tableView indexPathsForVisibleRows];
BOOL upHalf = true;
int halfIndex = indexArray.count / 4;
if (indexPath.row > [[indexArray objectAtIndex:halfIndex] row]) {
upHalf = false;
}
[self showOrderNumPopover:cell isUpHalf:upHalf];
[orderNumViewController release];
}
-(void)showOrderNumPopover:(OrderOnlineCell *)cell isUpHalf:(BOOL)upHalf{
orderNumPopover.popoverContentSize = CGSizeMake(400, 320);
CGRect popoverRect = CGRectMake(cell.bounds.origin.x + cell.bounds.size.width - 100,
cell.bounds.origin.y,
27, 32);
UIInterfaceOrientation orientation = self.interfaceOrientation;
UIPopoverArrowDirection direction = UIPopoverArrowDirectionUnknown;
if ((orientation == UIInterfaceOrientationPortrait) || (orientation == UIInterfaceOrientationPortraitUpsideDown)) {
if (upHalf) {
direction = UIPopoverArrowDirectionUp;
}else {
direction = UIPopoverArrowDirectionDown;
}
}else {
direction = UIPopoverArrowDirectionRight;
}
[orderNumPopover presentPopoverFromRect:popoverRect
inView:cell
permittedArrowDirections:direction
animated:YES];
}
本文出自 “何必呢” 博客,请务必保留此出处http://afantihust.blog.51cto.com/2231549/533976
如何解决可以参考iPhone应用程序编程指南 http://www.apple.com.cn/developer/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TextandWeb/TextandWeb.html#//apple_ref/doc/uid/TP40007072-CH20-SW16
大体思路是:暂时调整一或多个视图的尺寸和位置,从而使文本对象可见。管理带有键盘的文本对象的最简单方法是将它们嵌入到一个UIScrollView(或其子类,如UITableView)对象。当键盘被显示出来时,需要做的只是调整滚动视图的尺寸,并将目标文本对象滚动到合适的位置。为此,在UIKeyboardDidShowNotification通告的处理代码中需要进行如下操作:
1. 取得键盘的尺寸。
2. 将滚动视图的高度减去键盘的高度。
3. 将目标文本框滚动到视图中。
但有时会碰到要编辑字段不在UIScrollView中的情况,比如烟草项目中点击靠近底部的烟草信息,弹出的popover可能会被弹出的键盘遮盖,这时通过简单的调整popover箭头方向即可实现弹出窗口随弹出键盘滑动的效果,当iPad竖着放置时点击列表中靠上部的行,箭头朝上;点击靠下部的行,箭头朝下;iPad横向放置时箭头朝右,效果如图所示:
[align=center]iPad竖着放置时点击列表中靠上部的行,箭头朝上[/align]
[align=center] [/align]
[align=center]点击靠下部的行,箭头朝下[/align]
[align=center]竖向放置弹出键盘效果[/align]
[align=center] [/align]
[align=center]横向放置时箭头朝右[/align]
[align=center]横向放置弹出键盘效果[/align]
代码如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
OrderNumViewController *orderNumViewController = [[OrderNumViewController alloc] init];
orderNumViewController.containerViewController = self;
if (orderNumPopover == nil) {
orderNumPopover = [[UIPopoverController alloc] initWithContentViewController:orderNumViewController];
}else {
orderNumPopover.contentViewController = orderNumViewController;
}
OrderOnlineCell *cell = (OrderOnlineCell *)[tableView cellForRowAtIndexPath:indexPath];
NSArray *indexArray = [tableView indexPathsForVisibleRows];
BOOL upHalf = true;
int halfIndex = indexArray.count / 4;
if (indexPath.row > [[indexArray objectAtIndex:halfIndex] row]) {
upHalf = false;
}
[self showOrderNumPopover:cell isUpHalf:upHalf];
[orderNumViewController release];
}
-(void)showOrderNumPopover:(OrderOnlineCell *)cell isUpHalf:(BOOL)upHalf{
orderNumPopover.popoverContentSize = CGSizeMake(400, 320);
CGRect popoverRect = CGRectMake(cell.bounds.origin.x + cell.bounds.size.width - 100,
cell.bounds.origin.y,
27, 32);
UIInterfaceOrientation orientation = self.interfaceOrientation;
UIPopoverArrowDirection direction = UIPopoverArrowDirectionUnknown;
if ((orientation == UIInterfaceOrientationPortrait) || (orientation == UIInterfaceOrientationPortraitUpsideDown)) {
if (upHalf) {
direction = UIPopoverArrowDirectionUp;
}else {
direction = UIPopoverArrowDirectionDown;
}
}else {
direction = UIPopoverArrowDirectionRight;
}
[orderNumPopover presentPopoverFromRect:popoverRect
inView:cell
permittedArrowDirections:direction
animated:YES];
}
本文出自 “何必呢” 博客,请务必保留此出处http://afantihust.blog.51cto.com/2231549/533976
相关文章推荐
- iPhone/iPad键盘弹出遮挡要编辑内…
- iOS开发 编辑框被系统弹出的软键盘遮挡问题
- iOS开发 编辑框被系统弹出的软键盘遮挡问题
- 关于iPhone/iPad的iOS系统自动弹出认证窗口问题
- iOS-键盘弹出遮挡问题
- iOS键盘弹出遮挡输入框问题
- iOS解决键盘弹出遮挡输入框问题
- android键盘弹出、关闭、遮挡问题
- Android 软键盘弹出时布局内指定内容上移实现及问题解决
- iOS讲解迷惑之键盘弹出遮挡输入框的问题
- 关于iPhone/iPad的iOS系统自动弹出认证窗口问题
- 弹出输入法软键盘,编辑框悬浮,及覆盖遮挡问题的解决
- Android 输入法键盘和activity页面遮挡和自动弹出问题解决
- iOS 解决autolayout下键盘弹出遮挡问题
- Ipad/Iphone键盘输入慢、切换数字键盘慢的问题-iOS
- 键盘弹出高度和遮挡问题
- iOS学习——键盘弹出遮挡输入框问题解决方案
- (转)Android 软键盘弹出时布局内指定内容上移实现及问题解决
- h5键盘遮挡输入框问题 、模仿微信输入框失去焦点时隐藏iphone的软键盘和聚焦时出现输入框
- Android 自定义弹出框 EditText获取光标后键盘遮挡,及初始化弹出键盘问题解决