在iOS8中设置scrollEnabled = NO后,UITextView scrollEnabled = YES无法正常工作 [英] UITextView scrollEnabled = YES not working after set scrollEnabled = NO in iOS8

查看:599
本文介绍了在iOS8中设置scrollEnabled = NO后,UITextView scrollEnabled = YES无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个用于检查 UITextView scrollEnabled 的演示。
它只包含1 UITextView 和2按钮启用和禁用滚动

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


  • 我在模拟器和设备iOS 8上测试,如果我点击禁用滚动按钮, UITextView 将正确禁用滚动,但之后我
    点击在启用滚动时, UITextView 将不会启用滚动

  • 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

但是,我在设备iOS9上测试,启用和禁用滚动工作正常。

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

推荐答案

问题是在iOS 8中,contentSize未调整更改scrollEnabled时正确。对enableScrollButtonPressed方法进行小幅调整将成功解决问题。

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];
}

这篇关于在iOS8中设置scrollEnabled = NO后,UITextView scrollEnabled = YES无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆