在包含 UITextView 和 UIImageView 的 UIScrollView 中滚动后触摸位置出现问题

发布于 2024-11-03 06:38:39 字数 851 浏览 1 评论 0原文

我试图在用户在 UITextView 上移动到屏幕上方时绘制用户的触摸,然后将其保存为 UIImageView 的图像。由于我希望图像与 UITextView 中的文本一起滚动(当需要滚动的长文本时,图像的位置应取决于文本),因此我在 UIScrollView 中添加了 UIImageView 和 UITextView。在直接可见视图区域中滚动和另存为图像没有问题。然而,触摸区域实际上仅限于直接可见区域(加载时滚动视图的大小)。滚动后,用户触摸的痕迹都被推到了原始视图的大小。

在 ViewWillLoad 中我有这些:

UIImage *image = [UIImage imageNamed:@"abc.png"];  

(abc 的大小为 670X5000,我不需要它完全显示,我把它做得超长,这样即使对于有大量文本的 textView 也能工作......这似乎并不帮助你...)

imageView = [[UIImageView alloc] initWithImage:image] ;
imageView.frame = CGRectMake (0,0,670,750); 
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(45, 100, 670, 850)]; 
textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 670, 750)];

(在肖像..风景的另一个设置)

我知道我设置不正确,但我不知道如何继续。

我尝试过使用边界,但效果不大。触摸仍然不正确(就像我在滚动后触摸视图中的一个点,而轨迹实际上比该点高得多......)

I am trying to draw user's touches as they move above the screen over a UITextView, then save it as a UIImageView's image. Since I want the image to scroll together with the text in the UITextView (when there is long text that requires scrolling, the position of the image should be hinged upon the text) and hence I added both the UIImageView and UITextView in a UIScrollView. The scrolling and saving as image in the immediate visible view area are no problem. However, the touch area is really only confined to the immediate visible area( size of the scrollview at load). Trace of the user's touch are all pushed up to the size of the original view are after I scrolled.

in ViewWillLoad I have these:

UIImage *image = [UIImage imageNamed:@"abc.png"];  

(abc has a size of 670X5000, i don't need it to display completely, I made it super long so that it will work even for a textView with lots of text...that doesn't seem to help thou...)

imageView = [[UIImageView alloc] initWithImage:image] ;
imageView.frame = CGRectMake (0,0,670,750); 
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(45, 100, 670, 850)]; 
textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 670, 750)];

(at portrait..another settings for landscape)

I know I am setting them incorrectly, but I don't know how to proceed.

I tried playing with the bounds but it's not doing much. The touches are still incorrect (like I would touch a point in the view after I scrolled, and the trace is actually way higher than that point...)

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

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

发布评论

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

评论(1

柒七 2024-11-10 06:38:39

尝试使用 UITouch 方法“locationInView”:

CGPoint pointInScrollview =  [touch locationInView:scrollView];

try using the UITouch method "locationInView":

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