0
의 CALayer하고있는 UITableViewCell은 그래서 CALayers 몇 가지 간단한 물건을 시도했다. 나는 거의 즉시 문제에 부딪쳤다. 나는 정말로 내가 여기에 뭔가 빠져 있다고 느낀다. 여기 내 코드가있다.내가 UITableViewCells에서 애니메이션을 실험하고 싶었다 수수께끼
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
NSString* title = [self.array objectAtIndex:indexPath.row];
cell.textLabel.text = title;
CALayer* layer = [CALayer layer];
layer.backgroundColor = [UIColor greenColor].CGColor;
layer.bounds = CGRectMake(10, 10, 50, 50);
[cell.contentView.layer addSublayer:layer];
return cell;
}
위의 코드는 예상대로 녹색 사각형을 추가합니다.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"did select");
CALayer* layer = [CALayer layer];
layer.backgroundColor = [UIColor purpleColor].CGColor;
layer.bounds = CGRectMake(50, 10, 50, 50);
UITableViewCell* cell = [self tableView:self.tableView cellForRowAtIndexPath:indexPath];
[cell.contentView.layer addSublayer:layer];
CGRect bounds = layer.bounds;
bounds.size.width = 200;
layer.bounds = bounds;
}
그러나이 코드는 예상대로 작동하지 않았습니다. 나는 자주색 사각형을 원했고 그 사각형은 더 큰 사각형으로 자랐습니다. 왜 그게 효과가 없었나요? 이 라인에서 실수가