UITableView & UITextField

本文介绍了一个iOS应用如何监听和响应键盘事件的方法,包括获取键盘高度并调整UITableView的contentInset及scrollPosition,以及针对UITableViewCellReorderControl进行定制化的显示处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

keyboard event
----------------------
float version = [[[UIDevice currentDevice] systemVersion] floatValue];

if (version >= 5.0)
{
[[NSNotificationCenter defaultCenter] addObserver:[AppProperty sharedInstancd]
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillChangeFrameNotification
object:nil];
}


get keyboard height
----------------------

NSDictionary *userInfo = [notification userInfo];
NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGFloat height = [aValue CGRectValue].size.height;


contentInset & scroll
----------------------

UITableView *table = (UITableView *)[self superview];
NSIndexPath *indexPath = [table indexPathForCell:self];


CGFloat height = [[AppProperty sharedInstancd] keyboardHeight];
table.contentInset = UIEdgeInsetsMake(0, 0, height, 0);

[table scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];


UITableViewCellReorderControl 滑块
UITableViewCellDeleteConfirmationControl 删除
-----------------------
if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"])
{
UIView* resizedGripView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))];
[resizedGripView addSubview:view];
[self addSubview:resizedGripView];


CGSize sizeDifference = CGSizeMake(resizedGripView.frame.size.width - view.frame.size.width, resizedGripView.frame.size.height - view.frame.size.height);
CGSize transformRatio = CGSizeMake(resizedGripView.frame.size.width / view.frame.size.width, resizedGripView.frame.size.height / view.frame.size.height);

// Original transform
CGAffineTransform transform = CGAffineTransformIdentity;

// Scale custom view so grip will fill entire cell
transform = CGAffineTransformScale(transform, transformRatio.width, transformRatio.height);

// Move custom view so the grip's top left aligns with the cell's top left
transform = CGAffineTransformTranslate(transform, -sizeDifference.width / 2.0, -sizeDifference.height / 2.0);

[resizedGripView setTransform:transform];

for(UIImageView* cellGrip in view.subviews)
{
if([cellGrip isKindOfClass:[UIImageView class]])
[cellGrip setImage:nil];


}
}


UITableViewCellReorderControl 滑块
-----------------------
for (UIView * view in self.subviews)
{
if ([NSStringFromClass([view class]) rangeOfString: @"Reorder"].location != NSNotFound)
{
for (UIView * subview in view.subviews)
{
if ([subview isKindOfClass: [UIImageView class]])
{

((UIImageView *)subview).image = nil;

}
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值