UITableView 左右滑动时,出现删除按钮的动画
2015-12-04 14:39
381 查看
我想大家搞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以上测试通过,大家如果还有更好的实现方式,请留言。谢谢。
实现:
在继承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以上测试通过,大家如果还有更好的实现方式,请留言。谢谢。
相关文章推荐
- easyui动态添加组件没有样式
- poj 1679 The Unique MST
- 滚动指定UITableViewCell到顶部
- Build Settings中的变量@rpath,@loader_path,@executable_path
- UI视图控件、视图嵌套、SubView、Tag 的使用
- Android UICC 实现框架和数据读写
- LeetCode(304)Range Sum Query 2D - Immutable
- LeetCode(304)Range Sum Query 2D - Immutable
- easyui-slider
- IOS 高斯模糊 (毛玻璃效果 UIVisualEffect)
- String的substring和subSequence的区别
- 关于uitableview上面的一块空白的问题
- django的request对象和response对象
- easyui--datetiembox日期组件
- iOS开发-UI控件:关于使用UISearchDisplayController
- [APUE]再读之 标准IO库
- easyui--timespinner时间微调组件
- 解决Value '0000-00-00 ' can not be represented as java.sql.Timest
- easyui--spinner
- spoj375 Query on a tree(树链剖分 边权 入门题)