【发布时间】:2014-01-22 03:21:24
【问题描述】:
我正在尝试从 CGContext 创建 UIImageView,但由于某种原因,图像在我的 iPad 版本(但不是 iPhone!)上略微偏离了目标。 我正在传递 textview 本身(也尝试传递 UIView 层......)。 我已经包含了 viewImage 的图片。显然,我希望图像由整个正方形组成,并完美地封闭“在此处查看您的翻转文本(完成后)”......
有什么想法吗?!
这是我的代码:
-(UIImage *)getImage:(UITextView *)v
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions([v frame].size, NO, [UIScreen mainScreen].scale);
} else {
UIGraphicsBeginImageContext([v frame].size);
}
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, -v.frame.origin.x, -v.frame.origin.y);
CGContextSaveGState(context);
[[self.view layer] renderInContext:context];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
这是从上下文渲染的 UIImage(帧原点的 x,y 坐标看起来不错....)
视图控制器有问题吗?我不认为我的设置异常...
这就是我希望返回 UIImage 的样子(或多或少):
【问题讨论】: