2015-02-06 69 views
0

//截圖代碼爲什麼我的UIView顯示當我截圖它

/* Capture the screen shoot at native resolution */ 
UIGraphicsBeginImageContextWithOptions(Grid.frame.size, Grid.opaque, 1.0f); 
[Grid.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

/* Render the screen shot at custom resolution */ 
CGRect cropRect = CGRectMake(0 ,0 , Grid.frame.size.width * 4, Grid.frame.size.height * 4); 
UIGraphicsBeginImageContextWithOptions(cropRect.size, Grid.opaque, 1.0f); 
[screenshot drawInRect:cropRect]; 
customScreenShot = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

/* Save to the photo album */ 
UIImageWriteToSavedPhotosAlbum(customScreenShot,self, @selector(thisImage:hasBeenSavedInPhotoAlbumWithError:usingContextInfo:), NULL); 

當過我使用它概述了灰我uiviews而是一個邊界,如果我按住電源和home鍵使用手動截圖同時這些灰色輪廓不會出現。

任何人都可以幫忙嗎?

+1

標題和正文報告有衝突,但無論如何,不​​會描述所需的行爲,這會使此問題有點混淆。 – nhgrif 2015-02-06 01:22:58

回答

0

檢查您是否只有整數非小數維(42.000或1337.000,而不是42.500或1337.1234)。這可能是您的顯示問題的來源

//using ceil to round the values to integer non-fractional dimensions 
    self.messageLabel.frame = CGRectMake(ceil(self.messageLabel.frame.origin.x), 
             ceil(self.messageLabel.frame.origin.y), 
             ceil(self.messageLabel.frame.size.width), 
             ceil(self.messageLabel.frame.size.height)); 

    UIGraphicsBeginImageContextWithOptions(self.messageLabel.bounds.size, self.messageLabel.opaque, 0.0f); 
    [self.messageLabel.view drawViewHierarchyInRect:self.messageLabel.bounds afterScreenUpdates:NO]; 
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
相關問題