Animation lagging of the navigation controller in pushViewController,
When debugging the navigation controller yesterday, we found that the animation was choppy during push. The code for the choppy problem was as follows:
1-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {2 UIViewController * newController = [[UIViewController alloc] init]; 3 newController. title = @ "new controller"; 4 [self. navigationController pushViewController: newController animated: YES]; 5}
At first, I thought it was a computer performance problem, so I didn't care about it. This problem still exists when I debug it again this morning, because the Controller after this switch is UITableViewController, the Code is as follows:
1-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {2 UITableViewController * newController = [[UITableViewController alloc] init]; 3 newController. title = @ "new controller"; 4 [self. navigationController pushViewController: newController animated: YES]; 5}
Then I am interested in this question. Why is it stuck when I switch to UIViewController? First, compare the differences between UITableViewController and UIViewController. The View of UITableViewController is a list, and the background color is white by default. The View of UIViewController is white in time and space, and the background is black. The black background is usually displayed for two reasons:
1. the background color is black.
2. The alpha value of UIColor is 0.
Is the View of UIViewController black by default? Verify it first.
1-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {2 UIViewController * newController = [[UIViewController alloc] init]; 3 UIColor * color = newController. view. backgroundColor; 4 NSLog (@ "Color: % @", color); 5 newController. title = @ "new controller"; 6 [self. navigationController pushViewController: newController animated: YES]; 7}
The output result of the control bar is:
2015-06-04 12:30:17.007 Weibo[5110:607] Color: (null)
The color attribute of the View of UIViewController is empty. It is obvious that the background is black because the color is transparent.
The verification result of UITableViewController is as follows:
1-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {2 UITableViewController * newController = [[UITableViewController alloc] init]; 3 UIColor * color = newController. view. backgroundColor; 4 NSLog (@ "Color: % @", color); 5 newController. title = @ "new controller"; 6 [self. navigationController pushViewController: newController animated: YES]; 7}
Output result:
2015-06-04 12:34:12.555 Weibo[5128:607] Color: UIDeviceRGBColorSpace 1 1 1 1
Therefore, the main cause of freezing is that the default color of the View of UIViewController is null, and the background color is transparent. This is not a lag, but because of the visual problem of overlapping transparent colors, you can set a background color.