您的位置:首页 > 产品设计 > UI/UE

UITableView 左右滑动时,出现删除按钮的动画。

2013-09-05 10:47 537 查看
我想大家搞IOS的都很容易调出UITableView左右滑动时出现的哪个删除按钮吧。大家可能也注意到了,当滑动时按钮是从右向左动画展开的,但再次点击CELL时,按钮直接就隐藏掉了。注意,这个不是点击edit时出来的哪个删除。上次找了些资料关于点击CELL后,这个删除动画再次从左向右的动画隐藏。就像IPHONE通话记录中的左右滑的删除按钮效果一样。

实现:

在继承tableViewcell的类中进行以下代码处理:

- (void)layoutSubviews {
[super layoutSubviews];

//动画隐藏系统删除按钮
[UIView animateWithDuration:.3 animations:^{

for (UIView *subview in self.subviews)
{
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"])
{
if (deleteVisable)
{
//隐藏动画
CGRect newFrame = subview.frame;
newFrame.origin.x = 252;
newFrame.size.width = 0;
subview.frame = newFrame;
deleteVisable = !deleteVisable;

//如果删除按钮隐藏的时候,要重新注册手执,否则左边出不来。
//[self registerGesture];
}
else
{ //展示动画
CGRect newFrame = subview.frame;
newFrame.origin.x = 222;
newFrame.size.width = 60;
subview.frame = newFrame;
deleteVisable = !deleteVisable;
}
}
/*
else if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 100;
subview.frame = newFrame;
}
else if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellReorderControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 200;
subview.frame = newFrame;
}
*/
}

} completion:^(BOOL finished){
}];
}

以上代码在IOS5。0以上测试通过,大家如果还有更好的实现方式,请留言。谢谢。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: