The application consists of the scrollview with a lots of textfield.
Basically, I could scroll the scroll view..
I'm having problem when I clicked on the textfield for input, then, clicking done of the keyboard, keyboard hides..
but the view or the scroll view is not responding or freezes... I can't scroll..
Pls help me.
.m file:
Code:
#define SCROLLVIEW_CONTENT_HEIGHT 870
#define SCROLLVIEW_CONTENT_WIDTH 320
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name: UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name: UIKeyboardDidHideNotification object:nil];
m_scrollView.contentSize = CGSizeMake(SCROLLVIEW_CONTENT_WIDTH, SCROLLVIEW_CONTENT_HEIGHT);
displayKeyboard = NO;
}
- (void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)keyboardDidShow: (NSNotification *)notif
{
if (displayKeyboard) {
return;
}
NSDictionary* info = [notif userInfo];
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
offset = m_scrollView.contentOffset;
CGRect viewFrame = m_scrollView.frame;
viewFrame.size.height -= keyboardSize.height;
m_scrollView.frame = viewFrame;
CGRect textFieldRect = [m_activeField frame];
textFieldRect.origin.y += 10;
[m_scrollView scrollRectToVisible: textFieldRect animated:YES];
displayKeyboard = YES;
}
- (void) keyboardDidHide: (NSNotification *)notif
{
if (!displayKeyboard) {
return;
}
m_scrollView.frame = CGRectMake(0, 0, SCROLLVIEW_CONTENT_WIDTH, SCROLLVIEW_CONTENT_HEIGHT);
m_scrollView.contentOffset = offset;
displayKeyboard = NO;
}
#pragma mark * Textfield Delegate Methods
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if (textField == m_userNameField)
{
//check username if exists
}
else if(textField == m_emailPrimaryField || textField == m_emailSecondaryField)
{
//check input for email formatting
}
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
BOOL bReturn = YES;
if (textField == m_userNameField || textField == m_firstNameField || textField == m_lastNameField)
{
//text entry filter only alphanum inputs
}
return bReturn;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
-(BOOL) textFieldShouldBeginEditing:(UITextField*)textField
{
m_activeField = textField;
return YES;
}
.h file
Code:
@interface NewUserViewController : UIViewController <UIScrollViewDelegate, UITextFieldDelegate>
{
BOOL displayKeyboard;
CGPoint offset;
UITextField *m_activeField;
....
}