導航控制器在pushViewController時的動畫卡頓問題,

來源:互聯網
上載者:User

導航控制器在pushViewController時的動畫卡頓問題,

昨天在調試導航控制器的時候發現在push的時候動畫有卡頓的現象,出現卡頓問題的代碼如下:

1 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {2     UIViewController* newController = [[UIViewController alloc] init];3     newController.title = @"新的控制器";4     [self.navigationController pushViewController:newController animated:YES];5 }

 

  一開始以為是電腦效能問題,就沒在管它,今天早上再次調試的時候還是有這個問題,因為這次切換後的控制器是UITableViewController,重新運行後發現卡頓現象沒了,代碼如下:

1 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {2     UITableViewController* newController = [[UITableViewController alloc] init];3     newController.title = @"新的控制器";4     [self.navigationController pushViewController:newController animated:YES];5 }

然後就對這個問題來興趣了,為什麼切換成UIViewController時會有卡頓的問題呢?先對比一下UITableViewController和UIViewController的不同之處,UITableViewController的View是一個列表,背景色預設為白色,UIViewController的View時空白的,背景顯示黑色。背景顯示黑色一般有兩個原因:

1、背景色是黑色的。

2、UIColor的alpha值是0。

難道UIViewController的View預設是黑色的?先來驗證一下。

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 = @"新的控制器";6     [self.navigationController pushViewController:newController animated:YES];7 }

控制條輸出結果是:

2015-06-04 12:30:17.007 Weibo[5110:607] Color: (null)

UIViewController的View的color屬性是空的,很明顯,背景顯示黑色的原因是因為顏色是透明的。

UITableViewController的驗證結果如下:

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 = @"新的控制器";6     [self.navigationController pushViewController:newController animated:YES];7 }

輸出結果:

2015-06-04 12:34:12.555 Weibo[5128:607] Color: UIDeviceRGBColorSpace 1 1 1 1

所以,導致卡頓的的罪魁禍首就是UIViewController的View的預設color為空白,背景色是透明的。這其實不是卡頓,而是由於透明顏色重疊後視覺上的問題,設定一個背景色就可以了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.