滚动时的 UITableViewCell 动画
我有一个 UITableView ,其中包含自定义 UITableViewCells 。这些单元格可以用动画打开和关闭。当用户滚动时我想关闭单元格。我通过发布如下通知来做到这一点:
[[NSNotificationCenter defaultCenter] postNotificationName:@"closeSwipedCell" object:nil];
这将调用一个方法,该方法在 UITableViewCell 的子类中执行简单的动画。这工作正常,但动画不会发生,直到用户再次停止滚动 UITableView。 是否可以在滚动表视图时执行此动画?
I have a UITableView with custom UITableViewCells in it. These cells can be opened and closed with an animation. When the user scrolls I would like to close the cell. I do this by posting a notification like this:
[[NSNotificationCenter defaultCenter] postNotificationName:@"closeSwipedCell" object:nil];
This will call a method which does my simple animation in my subclass of UITableViewCell. This is working fine but the animation won't happen until the user stops scrolling the UITableView again.
Is it possible to do this animation while scrolling the table view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里有一个关于如何滑动到单元格子菜单(如 twitter iPhone 应用程序)的详细说明。我认为这与您正在寻找的非常相似。它不使用通知来关闭单元格,而是使用 UIScrollViewDelegate 中的事件,正如其他评论者所建议的那样。
iDevRecipes
在 idevrecipes.com 上查找名为“Twitter iPhone 应用程序如何在桌子上实现侧滑”的帖子。
有很好的描述,但也有可供下载的代码。
Here's a great detailed explanation of how to do a swipe to a cell submenu, like the twitter iphone app. I think it's very similar to what your looking for. It doesn't use notifications to close a cell, it uses the events from the UIScrollViewDelegate as the other commenters have recommended.
iDevRecipes
look for the post on idevrecipes.com called "How does the Twitter iPhone app implement side swiping on a table".
There's good description but also code to download.
您应该能够侦听
UIScrollViewDelegate
方法scrollViewDidScroll:
并然后触发您的事件。查看 有关 UIScrollViewDelegate 的 Apple 文档。
编辑:如果我不清楚,
UITableViewDelegate
符合UISCrollViewDelegate
。You should be able to listen to the
UIScrollViewDelegate
methodscrollViewDidScroll:
and fire your event then.Check out the Apple docs on UIScrollViewDelegate.
EDIT: If I was unclear, the
UITableViewDelegate
conforms to theUISCrollViewDelegate
.scrollViewDidScroll:
只能在用户滚动结束时调用。您可能想尝试使用scrollViewWillBeginDragging:
委托方法来触发通知,该方法肯定会在滚动操作开始时调用。还有几个
UIViewAnimationOptions
常量(IIRC,UIViewAnimationOptionBeginFromCurrentState
是我正在考虑的),它们会影响动画是否在另一个动画操作期间开始,例如滚动(跟踪) 。您需要将该选项与动画方法调用的
options:
参数中的现有动画选项进行“或”运算。scrollViewDidScroll:
may only be called at the end of the user scrolling. You may want to try firing your notification using thescrollViewWillBeginDragging:
delegate method, which will definitely be called at the beginning of the scroll action.There are also several
UIViewAnimationOptions
constants (IIRC,UIViewAnimationOptionBeginFromCurrentState
is the one I'm thinking of) that affect whether animation will begin during another animation action, such as scrolling (tracking).You'll need to
OR
that option with your existing animation options in theoptions:
parameter of your animation method call.