Animation lagging of the navigation controller in pushViewController,

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.