简体   繁体   中英

UITextView Inside UIScrollView Scrolling Parent as Text is Entered

I have a UIScrollView that contains a UITextView . As text is entered into the UITextView the UIScrollView will scroll to ensure that the text is entirely visible in the content frame. I don't want this.

I've disabled scrolling on the UIScrollView , however this has no effect. Anyone know how to stop this? A sample project can be found here: http://cl.ly/1P1u3y302r3q1f1C063K .

Thanks!

I had similar issues with UITextView . It seems scrollEnabled property does not cancel autoscrolling. I have solved it by overriding setContentOffset: method.
The following preventScrolling flag might help:

@interface MyScrollView : UIScrollView
@property (nonatomic, assign) BOOL preventScrolling;
@end

@implementation MyScrollView 
@synthesize preventScrolling;
-(void) setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
{
    if(!self.preventScrolling) {
        [super setContentOffset:contentOffset animated:animated];
    }
}
@end

you have set the wrong contentSize: of scroll view....

always set the content size according to content inside scroll view, if content height and width is greater than scroll view height and width then only increase the content size else put it the same as its width and height of scroll view

[self.mainScrollView setContentSize:CGSizeMake(4096, 4096)];

instead of it put this contentsize:

[self.mainScrollView setContentSize:CGSizeMake(mainScrollView.frame.size.width, mainScrollView.frame.size.height)];

may this will help you

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