Nicolas Roy
Nicolas Roy

Reputation: 3803

Avoid animation on an UIView

So to make it simple I'm trying to have the same view as in iMessage: a reversed UITableView.

I have a rotated UITableView :

self.tableView.transform = CGAffineTransformMakeRotation(-M_PI);

Each UITableViewCell is also rotated to appear the right way:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        UITableViewCell *cell = [[UITableViewCell alloc] init];
        cell.transform = CGAffineTransformMakeRotation(M_PI);
        return cell;
}

When the keyboard appears, the frame of my UITableView is changed, so that the bottom of my UITableView follows the top of the keyboard. Same thing when the keyboard hides. To do this I use an animation.

My problem is that when the keyboards hide, the frame of the UITableView increases, and some new cells are displayed. As they are displayed, the delegate calls tableView:cellForRowAtIndexPath: and the animation also applies on the

cell.transform = CGAffineTransformMakeRotation(M_PI);

So I see my new cells rotating!

Is there any way I could avoid the animation on the rotation?

Upvotes: 2

Views: 1793

Answers (2)

tc.
tc.

Reputation: 33602

You need to disable animations if you don't want the setting of animatable properties to be animated:

BOOL wasEnabled = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];

cell.transform = CGAffineTransformMakeRotation(M_PI);

[UIView setAnimationsEnabled:wasEnabled];

On iOS 7, you can use [UIView performWithoutAnimation:...].

Also, I would avoid doing

self.tableView.transform = CGAffineTransformMakeRotation(-M_PI);

Last I checked (iOS 5 or 6?), this would cause the cell sizes to be incorrect, as if UITableView used its frame's width to decide how "wide" cells should be. Stick it in a view and set the transform of that view instead (or check that it does the right thing on each major OS version you need to support).

Upvotes: 3

Raviraj Jadeja
Raviraj Jadeja

Reputation: 849

Hey mate try to maintain a bool variable when you dont need the animation set the bool variable to false during some editing or any other event. So put the condition of bool variable if it is True then only go for animation.

regards and have a nice year ahead

Upvotes: 0

Related Questions