我想做一些事情来回应某些UITableView动画的结束.例如,我希望表视图单元格在通过scrollToRowAtIndexPath滚动到之后突出显示(通过selectRowAtIndexPath).
如何才能做到这一点?
小智 29
基本模板:
[UIView animateWithDuration:0.2 animations:^{
//do some animations, call them with animated:NO
} completion:^(BOOL finished){
//Do something after animations finished
}];
Run Code Online (Sandbox Code Playgroud)
示例:滚动到第100行.完成后,获取此行的单元格,并使用tag = 1的单元格内容视图到firstResponder:
[UIView animateWithDuration:0.2 animations:^{
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:100 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
} completion:^(BOOL finished){
//Do something after scrollToRowAtIndexPath finished, e.g.:
UITableViewCell *nextCell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:100 inSection:0]];
[[nextCell.contentView viewWithTag:1] becomeFirstResponder];
}];
Run Code Online (Sandbox Code Playgroud)
Bro*_*olf -3
好吧,如果您想在scrollToRowAtIndexPath 被触发后执行操作。
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)
您需要创建一个 CAAnimation 指针,例如
CAAnimation *myAnimation;
Run Code Online (Sandbox Code Playgroud)
然后将delgate设置为self
myAnimation.delegate = self;
Run Code Online (Sandbox Code Playgroud)
完成此操作后,将激活以下委托方法,您可以在其中放置代码:
- (void)animationDidStart:(CAAnimation *)theAnimation
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7034 次 |
最近记录: |