我怎么能这样做?任何的想法?
解决方法 Apple在此描述了一种方法: http://developer.apple.com/library/ios/#qa/qa1703/_index.html- (UIImage*)screenshot {// Create a graphics context with the target size// On iOS 4 and later,use UIGraphicsBeginImageContextWithOptions to take the scale into consIDeration// On iOS prior to 4,fall back to use UIGraphicsBeginImageContextCGSize imageSize = [[UIScreen mainScreen] bounds].size;if (NulL != UIGraphicsBeginImageContextWithOptions) UIGraphicsBeginImageContextWithOptions(imageSize,NO,0);else UIGraphicsBeginImageContext(imageSize);CGContextRef context = UIGraphicsGetCurrentContext();// Iterate over every window from back to frontfor (UIWindow *window in [[UIApplication sharedApplication] windows]) { if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) { // -renderInContext: renders in the coordinate space of the layer,// so we must first apply the layer's geometry to the graphics context CGContextSaveGState(context); // Center the context around the window's anchor point CGContextTranslateCTM(context,[window center].x,[window center].y); // Apply the window's transform about the anchor point CGContextConcatCTM(context,[window transform]); // Offset by the portion of the bounds left of and above the anchor point CGContextTranslateCTM(context,-[window bounds].size.wIDth * [[window layer] anchorPoint].x,-[window bounds].size.height * [[window layer] anchorPoint].y); // Render the layer hIErarchy to the current context [[window layer] renderInContext:context]; // Restore the context CGContextRestoreGState(context); }}// RetrIEve the screenshot imageUIImage *image = UIGraphicsGetimageFromCurrentimageContext();UIGraphicsEndImageContext();return image;}
并记住#import< QuartzCore / QuartzCore.h>
总结以上是内存溢出为你收集整理的objective-c – 使用UIButton截取UIView的截图全部内容,希望文章能够帮你解决objective-c – 使用UIButton截取UIView的截图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)