Ios 注释(图像和文本)子视图在保存后更改位置
我已经创建了一个基于PDF的应用程序。首先,我从文档目录获取PDF,然后将其转换为图像,然后使用Ios 注释(图像和文本)子视图在保存后更改位置,ios,swift,uiimageview,cgpdfdocument,Ios,Swift,Uiimageview,Cgpdfdocument,我已经创建了一个基于PDF的应用程序。首先,我从文档目录获取PDF,然后将其转换为图像,然后使用UIImageView&ScrollView以编程方式将所有图像设置为垂直 然后我设置了不同类型的注释,如符号,文本等。当我最终将其转换为图像并将其转换为PDF时,效果良好。我得到不同的结果,如下图所示 屏幕1:将原始图像大小转换为UIImageView大小,并带有适合的纵横比(因为我看起来像这种类型的屏幕),当我将原始大小转换为屏幕大小时,我存储了图像原始大小,并在屏幕2中添加注释后将图像转换为pd
UIImageView
&ScrollView
以编程方式将所有图像设置为垂直
然后我设置了不同类型的注释,如符号
,文本
等。当我最终将其转换为图像并将其转换为PDF时,效果良好。我得到不同的结果,如下图所示
屏幕1:将原始图像大小转换为UIImageView大小,并带有适合的纵横比(因为我看起来像这种类型的屏幕),当我将原始大小转换为屏幕大小时,我存储了图像原始大小,并在屏幕2中添加注释后将图像转换为pdf时使用它
屏幕2。当我完成定稿或转换为pdf时。结果查看屏幕2,更改注释或标志位置
解决的问题:
通过使用UIScrollView缩放:
override func viewWillLayoutSubviews() {
self.configureZoomScale()
}
func configureZoomScale() {
var xZoomScale: CGFloat = self.scrollView.bounds.size.width / self.pdfImage.bounds.size.width
var yZoomScale: CGFloat = self.scrollView.bounds.size.height / self.pdfImage.bounds.size.height
var minZoomScale: CGFloat = min(xZoomScale, yZoomScale)
//set minimumZoomScale to the minimum zoom scale we calculated
//this mean that the image cant me smaller than full screen
self.scrollView.minimumZoomScale = minZoomScale
//allow up to 4x zoom
self.scrollView.maximumZoomScale = 4
//set the starting zoom scale
self.scrollView.zoomScale = minZoomScale
}
func viewForZooming(in scrollView: UIScrollView) -> UIView?{
return pdfFinalImage
}
显示一些代码,说明如何使用addSubView在图像上放置批注。getUIImageView.addSubview(gestureView)//gestureView是UIView,getUIImageView是UIImageView。在你的问题中添加代码,你添加的相关代码越多,对读者的帮助就越大。任何人都知道添加后转换图像时的计算(
符号
&文本
)得到完全不同的注释点(“符号”和“文本”)动态。
override func viewWillLayoutSubviews() {
self.configureZoomScale()
}
func configureZoomScale() {
var xZoomScale: CGFloat = self.scrollView.bounds.size.width / self.pdfImage.bounds.size.width
var yZoomScale: CGFloat = self.scrollView.bounds.size.height / self.pdfImage.bounds.size.height
var minZoomScale: CGFloat = min(xZoomScale, yZoomScale)
//set minimumZoomScale to the minimum zoom scale we calculated
//this mean that the image cant me smaller than full screen
self.scrollView.minimumZoomScale = minZoomScale
//allow up to 4x zoom
self.scrollView.maximumZoomScale = 4
//set the starting zoom scale
self.scrollView.zoomScale = minZoomScale
}
func viewForZooming(in scrollView: UIScrollView) -> UIView?{
return pdfFinalImage
}