2

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?

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Nicolas Roy
  • 3,773
  • 5
  • 27
  • 42
  • What is your intention here? Why are you trying to flip a table view by 180°? Do you simply want to reverse the order of cells in the table view? – neilco Dec 26 '13 at 12:41
  • I want to reverse it to have, as in the iMessage App, the cells arriving from the bottom (like that : http://stackoverflow.com/questions/5679835/uitableview-anchor-rows-to-bottom ) – Nicolas Roy Dec 26 '13 at 13:23
  • If all you want it to have the newest cells at the top, reverse the array that provides the data for the cells. – neilco Dec 26 '13 at 13:50
  • It's more than that, I want the first cell to be at the bottom of the screen, and to reverse the scroll. Just like iMessage ! – Nicolas Roy Dec 26 '13 at 13:59
  • Programmatically scroll the table view to the bottom. You're making this harder than it needs to be. – neilco Dec 26 '13 at 14:02
  • But when there is only one or two cells, they still stick to the top of the screen, don't they ? :/ – Nicolas Roy Dec 26 '13 at 14:15
  • Just like [Messages](http://cl.ly/T62G), yes. – neilco Dec 26 '13 at 16:25

2 Answers2

3

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).

tc.
  • 33,468
  • 5
  • 78
  • 96
0

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

Raviraj Jadeja
  • 849
  • 6
  • 17