2014-10-28 50 views
0

我已经插入一个UIView到我在我的故事板视图内容视图,我需要使用方法适合大型的UIView到

UIGraphicsBeginImageContext(createBoard.layer.frame.size) 
createBoard.layer.renderInContext(UIGraphicsGetCurrentContext()) 

let image = UIGraphicsGetImageFromCurrentImageContext() 
UIGraphicsEndImageContext() 

//Save it to the camera roll 
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil) 

利用这一图像在1000像素X 1000像素,但是我觉得是迅速重新调整视图以显示在我的显示器上,就像我在1000像素上拍摄图像时一样。我的问题是,我可以制作一个1000px x 1000px的UIView,并将其缩小以显示给用户,但是当拍摄图像时,它会在原始的1000px上执行此操作?

+0

问题可能是您没有考虑不同比例因子(视网膜/非视网膜)。你可以尝试使用'UIGraphicsBeginImageContextWithOptions(_ size:CGSize,_ opaque:Bool,_ scale:CGFloat)'并将0传递给刻度(它会根据设备的屏幕自然缩放因子自动设置刻度) – Alladinian 2014-10-28 16:01:10

+0

@Alladinian工作!非常感谢你! – 2014-10-28 16:06:17

+0

不客气!很高兴帮助你。作为答案添加。 – Alladinian 2014-10-28 16:09:50

回答

1

问题可能是您没有考虑不同比例因子(视网膜/非视网膜)。

你可以尝试使用:

UIGraphicsBeginImageContextWithOptions(_ size: CGSize, _ opaque: Bool, _ scale: CGFloat) 

,并通过0至刻度(它会自动将根据设备的屏幕自然比例因子的比例)

最后,如果你的目标iOS7 +您也可以使用视图快照更新的API:

-drawViewHierarchyInRect:afterScreenUpdates: 

as described here