本文主要是介绍iPhone/iPad键盘弹出遮挡要编辑内…,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
2011-04-02 16:17:31
标签: 键盘 iPhone keyboard 遮盖 popover
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。 http://afantihust.blog.51cto.com/2231549/533976
当系统收到显示键盘的请求时,就从屏幕的底部滑出键盘,并将它放在应用程序内容的上方。由于键盘位于内容的上面,所以有可能遮掩住用户希望编辑的文本对象,只能盲操^_^
如何解决可以参考iPhone应用程序编程指南 http://www.apple.com.cn/developer/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide
大体思路是:暂时调整一或多个视图的尺寸和位置,从而使文本对象可见。管理带有键盘的文本对象的最简单方法是将它们嵌入到一个UIScrollView(或其子类,如UITableView)对象。当键盘被显示出来时,需要做的只是调整滚动视图的尺寸,并将目标文本对象滚动到合适的位置。为此,在UIKeyboardDidShowNotific ation通告的处理代码中需要进行如下操作:
1. 取得键盘的尺寸。
2. 将滚动视图的高度减去键盘的高度。
3. 将目标文本框滚动到视图中。
1. 取得键盘的尺寸。
2. 将滚动视图的高度减去键盘的高度。
3. 将目标文本框滚动到视图中。
但有时会碰到要编辑字段不在UIScrollView中的情况,比如烟草项目中点击靠近底部的烟草信息,弹出的popover可能会被弹出的键盘遮盖,这时通过简单的调整popover箭头方向即可实现弹出窗口随弹出键盘滑动的效果,当iPad竖着放置时点击列表中靠上部的行,箭头朝上;点击靠下部的行,箭头朝下;iPad横向放置时箭头朝右,效果如图所示:

iPad竖着放置时点击列表中靠上部的行,箭头朝上

点击靠下部的行,箭头朝下

竖向放置弹出键盘效果

横向放置时箭头朝右

横向放置弹出键盘效果
代码如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
-(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 = UIPopoverArrowDirectionU nknown;
if ((orientation == UIInterfaceOrientationPo rtrait) || (orientation == UIInterfaceOrientationPo rtraitUpsideDown)) {
if (upHalf) {
direction = UIPopoverArrowDirectionU p;
}else {
direction = UIPopoverArrowDirectionD own;
}
}else {
direction = UIPopoverArrowDirectionR ight;
}
}
本文出自 “何必呢” 博客,请务必保留此出处http://afantihust.blog.51cto.com/2231549/533976
这篇关于iPhone/iPad键盘弹出遮挡要编辑内…的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!