简体   繁体   中英

Problems with touch position after scrolling in UIScrollView that contains a UITextView and UIImageView

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...)

尝试使用UITouch方法“ locationInView”:

CGPoint pointInScrollview =  [touch locationInView:scrollView];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM