スクリーンショット、960*640 ですが、画像の上部に 44 ピクセルの透明なステータス バーがあります。
高さ916pixの写真を撮るには?上部にある空白のバーは必要ありません。
これが私のコードです:
-(void)takeScreenShot{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]){
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0f);
}else{
UIGraphicsBeginImageContext(imageSize);
}
[window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
//
NSString *documentsDirectory= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *filePath= [documentsDirectory stringByAppendingPathComponent:@"SYS_screen_shot@2x.png"];
//
[data writeToFile:filePath atomically:YES];
}