2014-01-27 20 views
1

我有加入到UIToolbar一個UISegmentedControl名稱爲UISegmentedControl選擇的段消失編程

UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame]; 
toolbar.barStyle = UIBarStyleBlack; 
toolbar.translucent = YES; 
toolbar.barTintColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1.0]; 
[self.view addSubview:toolbar]; 

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"Last week", @"Last month", @"All time"]; 
[segmentedControl setSelectedSegmentIndex:0]; 
[toolbar addSubview:segmentedControl]; 

工具欄然後被添加到一個視圖控制器。當我拍攝視圖控制器的截圖時,會發生奇怪的事情。所選段的標題消失。

屏幕截圖正在使用採取:

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, [[UIScreen mainScreen] scale]); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

呈現的視圖: enter image description here

截圖: enter image description here

上哪裏開始尋找將理解任何指針。

回答

3

我把它換成

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 

隨着

[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES]; 

而現在它按預期工作。仍然不明白爲什麼會發生。

請注意,drawViewHierarchyInRect:afterScreenUpdates:僅限iOS 7。

+0

任何一個想法? drawViewHierarchyInRect:afterScreenUpdates:YES對我們有一些其他的問題... – x2on

+0

'drawViewHierarchyInRect:afterScreenUpdates:'給你造成了什麼問題? –

+0

它有時慢 – x2on