Thật ra, không có câu trả lời nào trong số này phù hợp. Đây là cách bạn làm điều đó để có được ảnh chụp màn hình của tất cả mọi thứ bao gồm điều khiển điều hướng
-(void) takeScreenshot
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
//its iphone
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480 || result.width == 480)
{
// iPhone Classic
screenRect = CGRectMake(0, 0, 320, 480);
}
if(result.height == 568 || result.width == 568)
{
// iPhone 5
screenRect = CGRectMake(0, 0, 320, 568);
}
}
else
{
//its pad
screenRect = CGRectMake(0, 0, 768, 1024);
}
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// This code is for high resolution screenshot
UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0);
//this was pre iOS 7.0
//[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
// iOS 7.x -->
[[[[UIApplication sharedApplication] windows] objectAtIndex:0] drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES]; // Set To YES
UIImage *viewImage2 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData* imageData2 = UIImageJPEGRepresentation(viewImage2, 1.0);
NSString* incrementedImgStr2 = [NSString stringWithFormat: @"UserScreenShotPic.jpg"];
// Now we get the full path to the file
NSString* fullPathToFile3 = [documentsDirectory stringByAppendingPathComponent:incrementedImgStr2];
[imageData2 writeToFile:fullPathToFile3 atomically:NO];
}
Nguồn
2016-08-18 22:01:56
Làm cách nào để tôi chụp màn hình một bộ điều khiển xem bao gồm thanh điều hướng TRƯỚC KHI đẩy nó? Tôi cần phải chụp màn hình màn hình điều khiển xem toàn màn hình đích. – cschuff
Nếu bạn có con trỏ tới bộ điều khiển chế độ xem, bạn có thể dễ dàng truy cập chế độ xem của bộ điều khiển chế độ xem đó ngay cả khi nó chưa được đẩy. –
Có, nhưng 1. thanh điều hướng không thuộc về chế độ xem và 2. tôi có thể truy cập NavigationBar của nó trước khi nó được đẩy hay không. Các thanh điều hướng xuất hiện trong VC2 khác với VC1. – cschuff