开发者

Attempting to set height of UITextView

I want to shrink the size of my UITextView (to 221 px) when the keyboard appears, and restore it to its normal height (337 px) when the keyboard disappears, so I did this:

- (void)keyboardWasShown:(NSNotification*)aNotification {
    NSDicti开发者_JS百科onary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    CGRect bkgndRect = inkTextField.superview.frame;
    bkgndRect.size.height += kbSize.height;
    [inkTextField.superview setFrame:bkgndRect];
    [inkScroller setContentOffset:CGPointMake(0.0, inkTextField.frame.origin.y-kbSize.height) animated:YES];
     inkTextField.frame=CGRectMake(1, -5, 285, 221);
}

// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
    UIEdgeInsets contentInsets = UIEdgeInsetsZero;
    inkScroller.contentInset = contentInsets;
    inkScroller.scrollIndicatorInsets = contentInsets;
    inkTextField.frame=CGRectMake(1, -5, 285, 337);
}

but this is not working. It's just using the height defined in the XIB file.


Ok your code looks ok, have you checked if the code is even being run using NSLog? If that is the case then heres an easier method: Create to IBActions:

- (IBAction)editBegan:(id)sender;
- (IBAction)editEnded:(id)sender;

Connect both IBActions with your textview. One with the connection editingDidBegin and the other one with editingDidEnd and in your .m simply put your code into each IBAction (the code for keyboardWasShown into editBegan and the code for keyboardWasDismissed into editEnded)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜