ios - UITextView top margin -


i'm using textview , noticed ios 7 leaves top margin default. see image in following enter image description here

i read different posts in common solution use:

[textviewtest setcontentinset:uiedgeinsetsmake(<#cgfloat top#>, <#cgfloat left#>, <#cgfloat bottom#>, <#cgfloat right#>)]; 

but insets custom solution particular device, textview, font size, , on. therefore, there no specific insets applicable solution... worst, have programmatically define different insets account ios devices , orientations.

good news found whenever textview becomes first responder , keyboard shown on screen, top margin disappears after keyboard has gone. way, i'm resizing contentinset on uikeyboarddidshownotification , uikeyboardwillhidenotification.

  • see image when keyboard did show:

enter image description here

  • see image when keyboard has gone:

enter image description here

is there way simulate keyboard show , hide? content inset disappears explain above.

i have tried making textview become first responder , resign it, approach user have see whole keyboard show-hide animation.

thanks in advance!

my code below:

- (void)viewdidload {     [super viewdidload]; }  - (void)viewwillappear:(bool)animated {     [super viewwillappear:animated];     [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(handlekeyboarddidshow:) name:uikeyboarddidshownotification object:nil];     [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(handlekeyboardwillhide:) name:uikeyboardwillhidenotification object:nil];     if(self.topmarginisalreadyresized == no) {         [self.mytextview becomefirstresponder]; // keyboard show eliminate top margin when view appears     } }  - (void)viewwilldisappear:(bool)animated {     [super viewwilldisappear:animated];     [[nsnotificationcenter defaultcenter] removeobserver:self]; }  - (void)handlekeyboarddidshow:(nsnotification *)notification {     if(self.topmarginisalreadyresized == no) {         self.topmarginisalreadyresized = yes; // once keyboard has shown when view appears, should hide manually         [self.mytextview resignfirstresponder];     }     nsvalue *keyboardrectasobject = [[notification userinfo] objectforkey:uikeyboardframeenduserinfokey];     cgrect keyboardrect = cgrectzero;     [keyboardrectasobject getvalue:&keyboardrect];     self.mytextview.contentinset = uiedgeinsetsmake(0.0f, 0.0f, keyboardrect.size.height, 0.0f); }  - (void)handlekeyboardwillhide:(nsnotification *)notification {     self.mytextview.contentinset = uiedgeinsetszero; } 

this happens because yor view controller has set the property automaticallyadjustsscrollviewinsets yes, if set no fine. see question , accepted answer more info.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -