0
こんにちはキーボードが表示されたときにbackgroundLoginViewを上に移動します。 superView-> scrollView-> backgroundView-> backgroundLoginView-> textFeild1(ログインID)とtextFeild2(パスワード) パスワードがキーボードに表示されたら、backgroundLoginViewが自動的に上に移動するときのコードです。 あなたはこの試みることができるMY backgroundLoginViewObjective-C Scrollキーボードが表示されて消滅したときに表示されない
問題
//LoginViewController.h
@interface LoginViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIView *backgroundLoginView;
@property (strong, nonatomic) IBOutlet UIView *backgroundView;
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@end
//LoginViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(hideKeyBoard)];
[_backgroundView addGestureRecognizer:tapGesture];
_scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width, CGRectGetMaxY(_backgroundView.frame));
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification*)aNotification
{
CGSize kbSize = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
NSTimeInterval duration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView animateWithDuration:duration animations:^{
UIEdgeInsets edgeInsets = UIEdgeInsetsMake(0, 0, kbSize.height, 0);
[_scrollView setContentInset:edgeInsets];
[_scrollView setScrollIndicatorInsets:edgeInsets];
}];
}
- (void)keyboardWillHide:(NSNotification*)aNotification
{
NSTimeInterval duration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView animateWithDuration:duration animations:^{
UIEdgeInsets edgeInsets = UIEdgeInsetsZero;
[_scrollView setContentInset:edgeInsets];
[_scrollView setScrollIndicatorInsets:edgeInsets];
}];
}
は、 。 –
このコードを使用する[here](http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present?rq=1) –
@HimanshuPatel canあなたは私のコードを編集する! –