Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27133

UITableViewCell animateWithDuration does not work

I have image view on my custom cell. All elements on cell have constraints. I have implement this method for animation my arrow. Rotation works good but without animation. I have debug cell and awake from nib method was invoked.

I have header that I built from the storyboard cell:

View controller callback:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    static NSString *cellIdentifier = @"SectionHeader";

    KNCategorySectionCell *sectionView = (KNCategorySectionCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    sectionView.index = section;
    sectionView.delegate = self;

    KNCategoryPoxy *category = [_categories objectAtIndex:section];

    [sectionView setupViewWithState:category.state];

    sectionView.categoryName.text = category.dictionary[@"name"];

    return sectionView;
}

Custom cell implementation of method:

- (void)setupViewWithState:(KNCategoryState)state
    {
        switch (state)
        {
            case KNCategoryStateStateCollapsed:
            {
                [self.contentView setBackgroundColor:[UIColor red:255 green:255 blue:255]];

            } break;

            case KNCategoryStateStateExpanded:
            {
                [UIView animateWithDuration:10.0f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{
                    self.arrowImage.transform = CGAffineTransformMakeRotation(M_PI_2);
                } completion:^(BOOL finished) {

                }];

                [self.contentView setBackgroundColor:[UIColor red:230 green:230 blue:230]];

            } break;
        }
    }

As I said the rotation is worked but it instantly rotate view to appropriate M_PI_2 and seems there is no animation.

I have used Xcode 6.1 and iOS 8.1 simulator for testing.

As additional I have implemented single tap gesture in custom cell and implemented this method:

- (void)singleTap
{
    [self.delegate sectionDidTappedWithIndex:self.index];
}

delegate it is my view controller which contains table that display all custom cells.

In view controller I have implemented method that set header expanded and reload data:

- (void)sectionDidTappedWithIndex:(NSInteger)index
{
        for (KNCategoryPoxy *category in _categories)
        {
            category.state = KNCategoryStateStateCollapsed;
        }

        KNCategoryPoxy *category = [_categories objectAtIndex:index];

        category.state = !category.state;

        [self.theTableView reloadData];
}

Upvotes: 0

Views: 1022

Answers (1)

Tibin Thomas
Tibin Thomas

Reputation: 1475

Try perform animations using UIView.commmitAnimations() eg:

 UIView.beginAnimations(“rotation”, context: nil)

    UIView.setAnimationDuration(0.8)

    cell.layer.transform = CATransform3DIdentity

    cell.alpha = 1

    cell.layer.shadowOffset = CGSize(width: CGFloat(0), height: CGFloat(0))

    UIView.commitAnimations()

also try to perform the operation inside willDisplayCell: Method.

Refer this http://www.thinkandbuild.it/animating-uitableview-cells/ solution to perform animations inside tableview cell

Upvotes: 1

Related Questions