swift - tableviewcell 重新加载动画 dispatch_async
swift - tableviewcell reload with animation with dispatch_async
我的单元格中有一个图标,当按下 fav 按钮时我想显示它 without reloading the whole table
.
所以我使用:
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.reloadData()
})
这会立即重新加载 table,我想要一个流畅的动画。
我发现了这个,它似乎适用于 objectiveC,我如何在 swift?
中执行此操作
/Put this code where you want to reload your table view
dispatch_async(dispatch_get_main_queue(), ^{
[UIView transitionWithView:<"TableName">
duration:0.1f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^(void) {
[<"TableName"> reloadData];
} completion:NULL];
});
使用动画重新加载 table 部分的简单方法是使用如下内容:
YOUR_TABLE.reloadSections(NSIndexSet(index: 0), withRowAnimation: UITableViewRowAnimation.Automatic) // You can try different UITableViewRowAnimations to see what you like
编辑:应该注意的是,这将使用指定的动画重新加载 table 视图的第一部分。您也可以将其放入异步调用中。
看来可以用这个方法
class func transitionWithView(view: UIView, duration: NSTimeInterval, options: UIViewAnimationOptions, animations: () -> Void, completion: ((Bool) -> Void)?)
等同于您使用OC的代码。
我的单元格中有一个图标,当按下 fav 按钮时我想显示它 without reloading the whole table
.
所以我使用:
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.reloadData()
})
这会立即重新加载 table,我想要一个流畅的动画。 我发现了这个,它似乎适用于 objectiveC,我如何在 swift?
中执行此操作/Put this code where you want to reload your table view
dispatch_async(dispatch_get_main_queue(), ^{
[UIView transitionWithView:<"TableName">
duration:0.1f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^(void) {
[<"TableName"> reloadData];
} completion:NULL];
});
使用动画重新加载 table 部分的简单方法是使用如下内容:
YOUR_TABLE.reloadSections(NSIndexSet(index: 0), withRowAnimation: UITableViewRowAnimation.Automatic) // You can try different UITableViewRowAnimations to see what you like
编辑:应该注意的是,这将使用指定的动画重新加载 table 视图的第一部分。您也可以将其放入异步调用中。
看来可以用这个方法
class func transitionWithView(view: UIView, duration: NSTimeInterval, options: UIViewAnimationOptions, animations: () -> Void, completion: ((Bool) -> Void)?)
等同于您使用OC的代码。