Search This Blog

Oct 5, 2010

UITextView Delegate Methods.

These delegate methods will automatically call according to the trigger.

Code for .h Controller.

@interface UIController : UIViewController <UITextViewDelegate>{

}

-(void)setViewMovedUp:(BOOL)movedUp;

Code for .m Controller.

-(void)textViewDidBeginEditing:(UITextView *)textView{
   
    [self setViewMovedUp:YES];
}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
   
    if([text isEqualToString:@"\n"]) {
        [txtViewDescription resignFirstResponder];
        [self setViewMovedUp:NO];
        return NO;
    }   
    return NO;
}

- (void)setViewMovedUp:(BOOL)movedUp{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    // Make changes to the view's frame inside the animation block. They will be animated instead
    // of taking place immediately.
    CGRect rect = self.view.frame;
    if (movedUp){       
        if(rect.origin.y == 0)
            rect.origin.y = self.view.frame.origin.y - 216;
    }
    else{       
        if(rect.origin.y < 0)
            rect.origin.y = self.view.frame.origin.y + 216;
    }   
    self.view.frame = rect;   
    [UIView commitAnimations];
}

No comments:

Post a Comment