//註冊事件和手勢
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShowNotify:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHideNotify:) name:UIKeyboardWillHideNotification object:nil];
myTextFeild.delegate = self;
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doDoubleTap)];
//雙擊,寫爲1變爲單擊
doubleTap.numberOfTapsRequired = 2;
doubleTap.numberOfTouchesRequired = 1;
[myScrollView addGestureRecognizer:doubleTap];
}
//打開軟鍵盤時調用
- (void)keyboardShowNotify:(NSNotification *)notify {
myScrollView.center = CGPointMake(myScrollView.center.x, myScrollView.center.y/2);
}
//關閉軟鍵盤時調用
- (void)keyboardHideNotify:(NSNotification *)notify {
myScrollView.center = CGPointMake(myScrollView.center.x, myScrollView.center.y*2);
}
//點擊鍵盤return鍵的時候調用
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
//雙擊scrollView的時候調用
- (void)doDoubleTap
{
[myTextFeild resignFirstResponder];
}