[英]Custom UITableView Cell Animation
我正在嘗試制作自定義單元格highlighted
動畫...但是它不起作用。 有什么想法可以使.alpa
改變動畫嗎?
ViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"myID";
TableViewCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
cell.selectedImg.frame = cell.contentView.frame;
cell.selectedImg.image = [ViewController imageFromColor:[UIColor colorWithRed:0.55 green:0.95 blue:0.68 alpha:0.0]];
cell.selectedImg.hidden = NO;
return cell;
}
TableViewCustomCell.m
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
if (highlighted) {
[UIView animateWithDuration:0.2 animations:^(void) {
self.selectedImg.alpha = 0.5;}];
}
else {
[UIView animateWithDuration:0.2 animations:^(void) {
self.selectedImg.alpha = 0.0;}];
}
}
PS我將有很多UITableViews
,它們都將具有相同的單元格樣式,因此我是否應該將cell.selectedImg
代碼放在TableViewCustomCell.m中? 如果是,正確的地方在哪里?
嘗試替換中的代碼
- (void)setHighlighted:(BOOL)高亮動畫:(BOOL)動畫
在TableViewCell.m中使用以下代碼:
[UIView animateWithDuration:0.2
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
if (highlighted) {
self.selectedImg.alpha = 0.5;
}
else {
self.selectedImg.alpha = 0;
}
}
completion:^(BOOL finished){
if (highlighted) {
self.selectedImg.alpha = 0;
}
else {
self.selectedImg.alpha = 0.5;
}
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.