当我截图时,为什么我的uiview会显示边框

时间:2015-02-06 01:20:01

标签: ios objective-c

//截图代码

/* 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,但如果我同时按住电源和主页按钮使用手动屏幕截图,则不会出现这些灰色轮廓。

任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分: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();