iphone - Moving view up to accommodate keyboard -
i have view multiple text fields , want same effect contacts application when click on text field otherwise hidden keyboard when comes up. when dismiss keyboard plan on moving view down properly.
i suspect changing frame value, need animated isn't jarring user.
advice? examples?
wrapping view in uiscrollview indeed way go. on textfielddidendediting
delegate, instead subscribe uikeyboarddidhidenotification
, uikeyboarddidshownotification
, when receive notification keyboard did hide/show scroll view appropriately. can post code examples keyboard notifications if need : )
edit figured i'd post code anyway - might find helpful:
you need declare listeners notifications:
nsobject hideobj = nsnotificationcenter.defaultcenter.addobserver(uikeyboard.didhidenotification, handlekeyboarddidhide); nsobject showobj = nsnotificationcenter.defaultcenter.addobserver(uikeyboard.didshownotification, handlekeyboarddidshow);
then action methods like:
void handlekeyboarddidshow(nsnotification notification) { scrollview.scrollrecttovisible(textfield.frame, true); } void handlekeyboarddidhide(nsnotification notification) { // scroll normal }
edit 2
so if you'd remove observers when view destroyed, first need ensure assign nsobject
s when adding observers use following code remove them:
nsnotificationcenter.defaultcenter.removeobserver(showobj); nsnotificationcenter.defaultcenter.removeobserver(hideobj);
hope helps.
Comments
Post a Comment