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

后端 未结 8 900
失恋的感觉
失恋的感觉 2021-02-07 02:49

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

  • I test on

8条回答
  •  面向向阳花
    2021-02-07 03:43

    Yeah you are right disabling and enabling scroll of textview is not working in iOS8 it may be a bug or anything else, let it be. We can disable or enable scroll of text view by just changing the ContentSize of textview .

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @property (weak, nonatomic) IBOutlet UITextView *myTextView;
    
    @end
    
     @implementation ViewController
    -(IBAction)enableScrollButtonPressed:(id)sender{
        CGSize scrollableSize = CGSizeMake(self.myTextView.bounds.size.width+20, self.myTextView.bounds.size.height+20);
        [self.myTextView setContentSize:scrollableSize];
    }
    
    -(IBAction)disableScrollButtonPressed:(id)sender{
        [self.myTextView setContentOffset:CGPointMake(0, 0)];
        [self performSelector:@selector(StopScroll) withObject:nil afterDelay:0.1];
    }
    
    -(void)StopScroll{
        CGSize scrollableSize = CGSizeMake(self.myTextView.bounds.size.width, self.myTextView.bounds.size.height/2);
        [self.myTextView setContentSize:scrollableSize];
    }
    
    @end
    

    I had tested the above code it is working fine for me i'am using xcode 7.2.1 and iOS 8.3. Give it a try and let me know the result

提交回复
热议问题