进入UITableViewCell的编辑模式时同时动画 [英] Simultaneous animation when entering editing mode of UITableViewCell

查看:50
本文介绍了进入UITableViewCell的编辑模式时同时动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当通过 setEditing:animated: UITableViewCell 中进入编辑模式时,会出现一个(隐式)动画,其中单元格向右移动并显示删除按钮"在左侧.

when entering the editing mode in a UITableViewCell through setEditing:animated:, there is an (implicit) animation where the cells move right and the delete "buttons" appear at the left.

在进入编辑模式时(可能具有相同的开始时间,持续时间,时序曲线和很快?(实际上,我正在尝试同步更改单元格子层的宽度.)

How do I manage, probably with Core Animation features, to run a second animation simultaneously to the first animation when entering editing mode, i.e. with the the same starting time, duration, timing curve, and so on? (I'm actually trying to change the width of a cell's sublayer synchronously.)

我研究了核心动画编程指南,并在自定义 UITableViewCell 类中尝试了某些技术,例如通过覆盖 willTransitionToState:.原则上,一切都很好,但是,我只能一个接一个地制作动画,但不能同时制作.

I studied the Core Animation Programming Guide and tried some of the techniques in a custom UITableViewCell class, for example by overriding willTransitionToState:. In principle, everything works well, however, I can only manage to have the animations one after the other, but not simultaneously.

任何建议都将不胜感激.

Any advice is greatly appreciated.

推荐答案

好的,它比我最初想象的要简单得多.通过正确初始化自定义 UITableViewCell 中的层(或视图),可以轻松实现我所寻求的行为.但是,我意识到顺序以及例如是否操纵边界或框架属性非常重要.

Alright, it's much simpler than I initially thought. The behavior I sought can rather easily be achieved by correctly initializing the layers (or views) in the custom UITableViewCell. However, I realized that the order and, e.g., whether you manipulate bounds or frame properties is quite important.

以下代码段对分组 UITableView 中的单元格进行了工作.在此示例中,将 CAGradientLayer (作为 CALayer 的示例)添加为 UIView 的子层,而UIView 本身又被添加为子视图到单元格的 self.contentView .调整了子视图的框架以适合contentView.该代码例如进入自定义 UITableViewCell :

The following code snippet does the job for a cell in a grouped UITableView. In this example, a CAGradientLayer (as an example for a CALayer) is added as a sublayer to a UIView, which itself is added as a subview to self.contentView of the cell. The subview's frame is tweaked to fit into the contentView. The code goes, e.g., into initWithStyle:reuseIdentifier: of a custom UITableViewCell:

CGRect realFrame = self.contentView.frame;
realFrame.size.width += 20;
UIView *gradientView = [[UIView alloc] initWithFrame:realFrame];

CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init];
gradientLayer.anchorPoint = CGPointMake(0.0, 0.0);
gradientLayer.frame = gradientView.frame;
gradientLayer.position = CGPointMake(0.0, 0.0);
[gradientLayer setColors:[NSArray arrayWithObjects:(id)[[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0] CGColor], (id)[[UIColor clearColor] CGColor], nil]];
gradientLayer.startPoint = CGPointMake(0.5, 0.0);
gradientLayer.endPoint = CGPointMake(0.5, 1.0);

gradientView.layer.masksToBounds = YES;
gradientView.layer.cornerRadius = 8.0;

[gradientView.layer insertSublayer:gradientLayer atIndex:0];
[self.contentView addSubview:gradientView];

gradientView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

[gradientView release];
[gradientLayer release];

这篇关于进入UITableViewCell的编辑模式时同时动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆