问题描述
限时送ChatGPT账号..我在 pdf 上创建了一个自定义视图 (SignatoryView),当我单击导航栏中的添加按钮时,它将在 PDF 视图上添加该 SignatoryView,并且根据我的选择,我可以将该签名视图移动/拖动到任何位置.
I took one custom view (SignatoryView) on pdf, When I click on Add button from Navigation bar, it will add that SignatoryView on PDF view and according to my choice I can move/drag that signatory view to any location.
问题:当我在 pdf 上移动那个签名视图时,它超出了 pdfView 的边缘.(左,右,下和上也)
Problem: When I am moving that signatory view on pdf, it is going outside edges of pdfView. (Left, right, bottom and top also)
这是演示:
它不应该超出它的边界,它应该只能在 PDF 视图的内部边缘移动.
It should not go beyond its boundaries, it should be movable only inside edges on PDF view.
我如何才能做到这一点?这里是完整的项目代码
How I can achieve this ? Here is the complete project code
推荐答案
你只需要得到你签名的一半宽度和一半高度,并在设置它的新中心位置时添加或从原点减去它x 和/或 y:
You just need to get half of the width and half of the height of your signature and when setting the new center position of it add or subtract it from the origin x and/or y:
let minX = frame!.width/2
let minY = frame!.height/2
let maxX = pdfView.frame.width-minX
let maxY = pdfView.frame.height-minY
customView1?.center = CGPoint(
x: min(maxX, max(minX, touchLocation!.x)),
y: min(maxY ,max(minY, touchLocation!.y)))
这篇关于在 PDFView 上移动/拖动时如何限制位置视图?(迅速)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论