Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView scrollEnabled = YES not working after set scrollEnabled = NO in iOS8

Tags:

I create a demo for checking UITextView scrollEnabled. It only contains 1 UITextView and 2 button enable and disable scroll

  • I test on simulator and device iOS 8, if I click the disable scroll button, the UITextView will disable scroll correctly, but after that I click on enable scroll, the UITextView won't enable scroll

  • However, I test on device iOS9, the enable and disable scroll work well.

    #import "ViewController.h"  @interface ViewController ()      @property (weak, nonatomic) IBOutlet UITextView *myTextView;  @end  @implementation ViewController  - (void)viewDidLoad {     [super viewDidLoad]; }  - (IBAction)enableScrollButtonPressed:(id)sender{     self.myTextView.scrollEnabled = YES; }  - (IBAction)disableScrollButtonPressed:(id)sender{     self.myTextView.scrollEnabled = NO; }  @end 

Any idea to fix this problem? If someone don't understand my explain please check my demo project
Any help or suggestion would be great appreciated

like image 672
Linh Avatar asked May 11 '16 03:05

Linh


1 Answers

The problem is that in iOS 8, contentSize is not adjusted correctly when scrollEnabled is changed. A small adjustment to your enableScrollButtonPressed method will successfully work around the problem.

-(IBAction)enableScrollButtonPressed:(id)sender {     self.myTextView.scrollEnabled = YES;     self.myTextView.contentSize = [self.myTextView sizeThatFits:self.myTextView.frame.size]; } 
like image 54
Brett Donald Avatar answered Oct 21 '22 10:10

Brett Donald