Domanda

I have a table view that I animate to a new position when pressing a button. It covers a small portion of the screen at the bottom and then pressing the button calls a method that makes it cover about half the screen. This way the user can choose a file from the table view.

However, it seems that when I call reloadData, the table view moves back to its original position, and I would like to stop that from happening so that the user doesn't need to press the button every time (such as with deleting a file, renaming a file, or adding a new file to the table view).

Any ideas how I could accomplish this?

I've included code. The file IBAction is what happens when the button is pressed.

-(IBAction)file:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];

if (self.tableView.frame.origin.y == 457) {
    [self tableAppear];
}
else {
   [self tableDisappear];
}
}

-(void)tableDisappear {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];

if ([[UIScreen mainScreen] bounds].size.height == 568) { [self.tableView setCenter:CGPointMake(160, 545)];

}
else { [self.tableView setCenter:CGPointMake(160, 545)];

}
[UIView commitAnimations];
}

-(void)tableAppear {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];

    if ([[UIScreen mainScreen] bounds].size.height == 568) { [self.tableView setCenter:CGPointMake(160, 390)];

    }
    else { [self.tableView setCenter:CGPointMake(160, 390)];


    }
    [UIView commitAnimations];

}
È stato utile?

Soluzione

This is most likely a consequence of auto layout (when the screen needs to be redrawn, all views will revert to the positions determined by their constraints rather then any frames that you set). You can turn off auto layout to see if this is the problem. If you want to use auto layout, then you need to do any moving or resizing of view using constraints rather than setting views.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top