How to fix a field adjustment code attached to a “grouped” UITableView?

Trying to achieve the appearance of a Grouped TableView with one element in each section and with a small number of fields (gives me a rounded image with the ability for the user to choose the color that they want),

It works for me. HOWEVER, when the user changes orientation, I had to use the didRotateFromInterfaceOrientation method (since willRotateToInterfaceOrientation does not work), BUT the effect is that you see that the fields change quickly in this fraction of a second after displaying the tableView.

QUESTION - Any way to correct the situation so that this transition is not visible?

- (void) removeMargins { CGFloat marginAdjustment = 7.0; CGRect f = CGRectMake(-marginAdjustment, 0, self.tableView.frame.size.width + (2 * marginAdjustment), self.tableView.frame.size.height); self.tableView.frame = f; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self removeMargins]; } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; [self removeMargins]; } 
0
source share
2 answers

I think the problem is that in willRotateToInterfaceOrientation the tableView frame has not yet been resized, so your frame calculations are incorrect. on didRotateFromInterfaceOrientation frame has already changed.

I think the easiest way to resolve this is to subclass UITableView and override layoutSubviews. This method is called every time a view frame changes in such a way that it may require changing it in subviews.

The following code worked for me without merging the animation:

 @interface MyTableView : UITableView { } @end @implementation MyTableView -(void) layoutSubviews { [super layoutSubviews]; CGFloat marginAdjustment = 7.0; if (self.frame.origin.x != -marginAdjustment) // Setting the frame property without this check will call layoutSubviews again and cause a loop { CGRect f = CGRectMake(-marginAdjustment, 0, self.frame.size.width + (2 * marginAdjustment), self.frame.size.height); self.frame = f; } } @end 
+1
source

You say that willRotateToInterfaceOrientation does not work, but you did not say why.

If the reason is that willRotateToInterfaceOrientation is not called then look at this question .

If you get this job, I believe that your other question will be resolved by myself.

0
source

All Articles