ios - UIScrollView programatically Scrolling -


i have uitextview inside uiscrollview needs automatically scroll once user starts editing it. because keyboard cover textview.

here code -

in viewdidload:

feedbackformview = [[uiscrollview alloc] initwithframe:cgrectmake(0, segmentedcontrol.frame.origin.x + self.segmentedcontrol.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)]; feedbackformview.backgroundcolor = [uicolor whitecolor]; feedbackformview.scrollenabled = yes; feedbackformview.delegate = self; feedbackformview.userinteractionenabled = yes; feedbackformview.showsverticalscrollindicator = yes; feedbackformview.contentsize = cgsizemake(320, 700);  commentsview = [[uitextview alloc] initwithframe:cgrectmake(5, emailfield.frame.origin.y + 40, 250, 150)]; commentsview.delegate = self; commentsview.layer.borderwidth = 2.0f; commentsview.layer.cornerradius = 5; 

and here's delegate method implementation -

-(void)textviewdidbeginediting:(uitextview *)textview{     cgpoint point = textview.frame.origin;     [scrollview setcontentoffset:point animated:yes]; } 

however, nothing happens.

your doing fine use feedbackformview instead of scrollview,while setting content offset in textviewdidbeginediting:method, have on below code

feedbackformview = [[uiscrollview alloc] initwithframe:cgrectmake(0, 50, 320, 200)]; feedbackformview.backgroundcolor = [uicolor whitecolor]; feedbackformview.scrollenabled = yes; feedbackformview.delegate = self; feedbackformview.userinteractionenabled = yes; feedbackformview.showsverticalscrollindicator = yes; feedbackformview.contentsize = cgsizemake(320, 700);  commentsview = [[uitextview alloc] initwithframe:cgrectmake(5, 40, 250, 150)]; commentsview.delegate = self; commentsview.layer.borderwidth = 2.0f; commentsview.layer.cornerradius = 5;  [feedbackformview addsubview:commentsview]; [self.view addsubview:feedbackformview]; 

in textview delegatemethod,

-(void)textviewdidbeginediting:(uitextview *)textview{   cgpoint point = textview.frame.origin;   [feedbackformview setcontentoffset:point animated:yes];  } 

hope hepls you...


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -