1
我正在研究一些將創建電子郵件並附加用戶發送的屏幕圖像。我使用下面的代碼來創建和附加圖像。以編程方式通過一些子視圖通過電子郵件發送圖像而不是其他人?
UIGraphicsBeginImageContext([self.view frame].size);
[[self.view layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *myImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIGraphicsBeginImageContext([self.view bounds].size);
[myImage drawInRect:CGRectMake(0, 0, [self.view bounds].size.width,[self.view bounds].size.height)];
myImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(myImage);
[mailer addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"blah"];
然而,這包括所有的子視圖,我要排除一個工具欄和分割視圖,只留下該視圖中的工具欄和文本框上方的視圖。我已經標記了所有相關的視圖和子視圖,但是如何使用這些標記創建包含我想要的圖像並排除我不想要的圖像?
謝謝!這是一個比我擔心的更簡單,更優雅的解決方案。 – 2012-08-09 14:01:46
還有一個問題:這就是我想要的,但現在工具欄所在的區域顯示爲空白的灰色空間。我如何獲得它上面的UIView來擴展以填充整個視圖(當然,沒有刪除我想包含的其他子視圖)? – 2012-08-09 14:08:44
將框架更改爲視圖的當前框架+您需要填充工具欄區域的其他區域。你可以用'CGRectMake'來做到這一點 – Dustin 2012-08-09 14:10:29