Reputation: 15138
here is my code:
-(void)setViewMovedUp:(BOOL)movedUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2]; // if you want to slide up the view
[UIView setAnimationBeginsFromCurrentState:YES];
CGRect rect = scroll.frame;
if (movedUp)
{
rect.size.height += kOFFSET_FOR_KEYBOARD;
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
}
else
{
rect.size.height -= kOFFSET_FOR_KEYBOARD;
rect.origin.y += kOFFSET_FOR_KEYBOARD;
}
scroll.frame = rect;
[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification *)notif {
[self setViewMovedUp:NO];
}
- (void)keyboardWillShow:(NSNotification *)notif{
[self setViewMovedUp:YES];
}
- (void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:self.view.window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:self.view.window];
}
- (void)viewWillDisappear:(BOOL)animated
{
// unregister for keyboard notifications while not visible.
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
The problem is, how can I spezify this to only work on TextView3, not TextView2 or TextView1. BackGround is, that TextView1 and TextView2 are doesn't need that becouse there are on top of my view. Only TextView3 is the TextView that is not readable because the keyboard is overlayed and the view must be corrected to be able to read what I write.
Upvotes: 0
Views: 1728
Reputation: 6160
assign a special tag for textView3 implement the TextView delegate mothode - (void)textViewDidBeginEditing:(UITextView *)textView;
here you will check for the textView tag if its equal to textView 3 tag call your function -(void)setViewMovedUp:(BOOL)movedUp
.
More code :
Ok you need to import the TextViewDelegate into your viewController like this : in .h viewController file -> viewController : UIViewController<UITextVIewDelegate>
Then in viewDidload for ex assign the tag like this : textView3.tag = 222;
Then take the delegate methode that i write it above "textViewDidBeginEdit" and inside make an if statment to check textView tag if equal to 222 call your function .
This the best i can describe right now because im writing this from iPhone ... Good luck.
Upvotes: 2