在包含 UITextView 和 UIImageView 的 UIScrollView 中滚动后触摸位置出现问题
我试图在用户在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 UITouch 方法“locationInView”:
try using the UITouch method "locationInView":