首先,我們在ViewController.h中
為隨縣等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及隨縣網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站設(shè)計(jì)、做網(wǎng)站、隨縣網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!@interface ViewController : UIViewController
@property (strong, nonatomic) UIScrollView* scrollView;
@property (strong, nonatomic) UITextField* textField;
@end
之后在ViewController.m
@implementation ViewController
- (void)viewDidLoad
{
[superviewDidLoad];
self.scrollView = [[UIScrollViewalloc] initWithFrame:CGRectMake(0, 0, 320, 600)];
[self.viewaddSubview:self.scrollView];
self.textField = [[UITextFieldalloc] initWithFrame:CGRectMake(50, 400, 100, 30)];
self.textField.backgroundColor = [UIColorwhiteColor];
[self.scrollViewaddSubview:self.textField];
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(textShowBegin:) name:UIKeyboardWillShowNotificationobject:nil];
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyBoardDidHidden) name:UIKeyboardWillHideNotificationobject:nil];
[self.textFieldaddTarget:selfaction:@selector(textFieldResign) forControlEvents:UIControlEventEditingDidEndOnExit];
}
-(void)keyBoardDidHidden
{
self.scrollView.contentInset = UIEdgeInsetsZero;
}
-(void)textFieldResign
{
[self.textFieldresignFirstResponder];
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
self.textField = textField;
}
-(void)textShowBegin:(NSNotification*)aNotification
{
NSDictionary* info = aNotification.userInfo;
NSLog(@"%@",info);
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0, 0, kbSize.height, 0);
self.scrollView.contentInset = contentInsets;
//獲取整個(gè)視圖的大小和位置
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, self.textField.frame.origin)) {
CGPoint scrollPoint = CGPointMake(0, self.textField.frame.origin.y - kbSize.height);
[self.scrollViewsetContentOffset:scrollPoint animated:YES];
}
}
下載地址 "TextFieldKB1119.zip" http://vdisk.weibo.com/s/Et2R_
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。