以下代码在iOS <7.0中可以正常工作.在iOS 7中,当UITextView正在更新时,滚动将变得不稳定且不稳定.我不确定这是否是iOS 7中的错误,或者我做错了什么.
TestController.h
//TODO: Add UITextView in storyboard and tie to textView outlet
#define MAX_TEXT_VIEW_CHARACTERS 1000
@interface TestController : UIViewController {
NSMutableString *_outputText;
NSTimer *_outputTimer;
}
@property (strong, nonatomic) IBOutlet UITextView *textView;
@end
Run Code Online (Sandbox Code Playgroud)
TestController.m
@implementation TestController
@synthesize textView;
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_outputText = [NSMutableString stringWithCapacity:MAX_TEXT_VIEW_CHARACTERS];
_outputTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(outputLine:) userInfo:nil repeats:YES];
}
-(void)outputLine:(NSTimer *) theTimer {
static int i = 0;
//Run this 100 times
if (i > 99) {
[_outputTimer invalidate];
return;
} …Run Code Online (Sandbox Code Playgroud) 我创建了一个按钮,为textView添加了一些文本,我希望它在按下时自动滚动到底部,以便用户能够看到添加的新文本.
我无法在Swift中使用此解决方案,因为我不了解Objective-C.有谁知道如何在Swift中滚动到textView的底部?谢谢.