[Reprinted]How to close keyboard

在iOS中處理鍵盤的關閉,多是透過resignFirstResponder某個input view

轉載一個通用作法的文章
The easy way to dismiss the keyboard in iOS

force UITextView to scroll to the top

當畫面中的UITextView被塞入了大量文字,且文字數量多到畫面可以scroll
這時候就需要透過撰寫程式碼的方式,強迫畫面重新scroll至最頂端,作法如下

- (void)viewDidLoad {
    [super viewDidLoad];
   
    NSString *verylongText = @"very looooooooooooong text";
    [self.myTextView setText:verylongText];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

    // make the UITextView scroll to top
    [self.myTextView scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO];
}