在 PDFView 上移动/拖动时如何限制位置视图?(迅速)

编程入门 行业动态 更新时间:2024-10-28 16:17:19
本文介绍了在 PDFView 上移动/拖动时如何限制位置视图?(迅速)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-30 02:13:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1388526.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:拖动   视图   位置   PDFView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!