在 UIScrollView 上绘制图像和线条

发布于 2024-09-05 09:42:52 字数 230 浏览 5 评论 0原文

我正在编写一个应用程序,其中一个 ViewController 正在显示一个显示图像的 UIScrollView。

我想加载一个图像(png 格式的图钉)并在 UIScrollView 图像的某些点上绘制它(并删除它)。

我还想在该图像中绘制贝塞尔路径(并删除它们)。

我已经编写了几个应用程序,但这是我第一次面对图形编程,不知道从哪里开始。

有什么建议吗?

谢谢!

I'm programming an app in which one of the ViewControllers is showing an UIScrollView that shows an image.

I'd like to load an image (pushpin in png format) and draw it (and delete it) in some points of the UIScrollView image.

I'd also would like to draw bezier paths in that image (and deleting them).

I've programmed several apps but this is the first time I face graphic programming and don't know where to start from.

Any suggestions?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杯敬自由 2024-09-12 09:42:52

您可以为添加到滚动视图的视图设置标签。

这意味着您稍后可以通过以下方式获取对该视图的引用:

    UIView * myView = (UIView*)[myScrollView viewWithTag:CONTENT_TAG];
    //Then add a pin
    [myView addSubView:myPinView];

如果您想再次删除 pin,您可以使用相同的方法,在 pinView 上设置标记并稍后获取对其的引用,然后对其调用removeFromSuperView。

您还可以选择为滚动内容和 pin 构建属性,但是上面的内容(假设您只需要与滚动视图一起引用它)可以减少很多代码,并且在我看来,实现更容易阅读(给出标签描述性名称如:

#define SCROLL_CONTENT_VIEW 9000
#define CONTENT_VIEW_PIN 9001

所以它是:

UIView * myView = (UIView*)[myScrollView viewWithTag:SCROLL_CONTENT_VIEW];
//and
UIView * myPin = (UIView*)[myView viewWithTag:CONTENT_VIEW_PIN];

希望这就是您想要的:)

You could set the tag for the view you add to the scrollView.

This means you can get a reference to the view later on by:

    UIView * myView = (UIView*)[myScrollView viewWithTag:CONTENT_TAG];
    //Then add a pin
    [myView addSubView:myPinView];

If you want to remove the pin again, you can use the same approach, set the tag on the pinView and get a reference to it later on and call removeFromSuperView on it.

You can also chose to build properties for both scroll content and pin, but the above (assuming you only need to reference it in conjunction with the scrollView) makes for a lot less code and, in my view, a easier to read implementation (giving the tags descriptive names like:

#define SCROLL_CONTENT_VIEW 9000
#define CONTENT_VIEW_PIN 9001

So it is:

UIView * myView = (UIView*)[myScrollView viewWithTag:SCROLL_CONTENT_VIEW];
//and
UIView * myPin = (UIView*)[myView viewWithTag:CONTENT_VIEW_PIN];

Hope this was what you were after:)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文