話很少說,上圖:框架
用到了TPKeyboardAvoiding框架,代碼以下:spa
在viewController中:
.net
#import "ViewController.h"3d
#import "TPKeyboardAvoidingScrollView.h"orm
@interface ViewController ()get
@end it
@implementation ViewControllerio
- (void)viewDidLoad {class
[super viewDidLoad];import
TPKeyboardAvoidingScrollView *scrollview = [[TPKeyboardAvoidingScrollView alloc]initWithFrame:self.view.frame];
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 500, 100, 100)];
textField.backgroundColor = [UIColor redColor];
[scrollview addSubview:textField];
[self.view addSubview:scrollview];
}