我坚持使用某种魔法:当我尝试更改UITextView框架(在本例中使用UiSlider)时,文本将绘制在除框架之外的其他(较小)区域中(多次调整大小).有趣的是,如果我们在尝试使框架更大时滑动得足够快,则会在非常正确的区域绘制文本.有人可以解释一下原因吗?我尝试布局,自动调整大小,设置内容大小和范围,但没有任何作用.
- (void)viewDidLoad { [super viewDidLoad]; _textView = [[UITextView alloc] initWithFrame:CGRectMake(10,10,100,100)]; _textView.backgroundColor = [UIColor greenColor]; _textView.text = @"some useless text which will be drawn bad"; [self.view addSubview:_textView]; UiSlider *slide = [[UiSlider alloc] initWithFrame:CGRectMake(10,130,20)]; [slide setValue:0.0]; [slide addTarget:self action:@selector(changedValue:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:slide]; } - (void)changedValue:(UiSlider *)slider { CGRect textViewFrame = _textView.frame; textViewFrame.size.width = [slider value] * 200; _textView.frame = textViewFrame; }
在调整大小之前
调整大小后