ios - When dismissing keyboard how do I keep my existing text fields in the same location? -
so have uiscrollview contains uitextfields , uilabels, , when user clicks inside uitextfield keyboard shows. need way allow user dismiss keyboard , try use swipe down gesture (as in messages). added gesture recognizer view in storyboard , added action header file. here method:
- (ibaction)swipekeyboarddown:(id)sender { if(self.movetextfield) { [self.movetextfield resignfirstresponder]; } }
i have if there testing when user has clicked on first text field, , when try swipe down of text field , labels move bottom of screen. there need keep text fields , labels in place? using auto layout , created them in storyboard.
this how view looks before swiping keyboard down:
and how looks after swiping down:
thanks help, , if more info needed please ask , can provide more.
backtrace:
2014-02-02 01:28:33.453 bjjdrillingapppro[512:70b] ( 0 bjjdrillingapppro 0x0001de82 -[addmoveviewcontrollerpro observevalueforkeypath:ofobject:change:context:] + 210 1 foundation 0x0116e8c7 nskeyvaluenotifyobserver + 362 2 foundation 0x01170206 nskeyvaluedidchange + 458 3 foundation 0x0112c8dd -[nsobject(nskeyvalueobservernotification) didchangevalueforkey:] + 120 4 foundation 0x010ffcc7 _nssetpointvalueandnotify + 185 5 uikit 0x00320cae -[uiscrollview(uiscrollviewinternal) _adjustcontentoffsetifnecessary] + 2622 6 uikit 0x0030384d -[uiscrollview setcontentsize:] + 354 7 bjjdrillingapppro 0x0002023d -[addmoveviewcontrollerpro keyboarddidhide] + 493 8 foundation 0x011f2bf9 __57-[nsnotificationcenter addobserver:selector:name:object:]_block_invoke + 40 9 corefoundation 0x017f8524 __cfnotificationcenter_is_calling_out_to_an_observer__ + 20 10 corefoundation 0x0175000b _cfxnotificationpost + 2859 11 foundation 0x0112c951 -[nsnotificationcenter postnotificationname:object:userinfo:] + 98 12 uikit 0x0071d6f5 -[uiinputviewtransition postnotificationsfortransitionstart] + 1004 13 uikit 0x007137e2 -[uiperipheralhost(uikitinternal) executetransition:] + 592 14 uikit 0x00715c0e -[uiperipheralhost(uikitinternal) setinputviews:animationstyle:] + 1029 15 uikit 0x00716019 -[uiperipheralhost(uikitinternal) setinputviews:animated:] + 72 16 uikit 0x00716063 -[uiperipheralhost(uikitinternal) setinputviews:] + 67 17 uikit 0x0070d2fa -[uiperipheralhost(uikitinternal) _reloadinputviewsforresponder:] + 1453 18 uikit 0x003e707c -[uiresponder _finishresignfirstresponder] + 163 19 uikit 0x003e719f -[uiresponder resignfirstresponder] + 265 20 uikit 0x0096b5f4 -[uitextfield resignfirstresponder] + 118 21 bjjdrillingapppro 0x0001dd70 -[addmoveviewcontrollerpro swipekeyboarddown:] + 288 22 uikit 0x00605e8c _uigesturerecognizersendactions + 230 23 uikit 0x00604b00 -[uigesturerecognizer _updategesturewithevent:buttonevent:] + 383 24 uikit 0x0060656d -[uigesturerecognizer _delayedupdategesture] + 60 25 uikit 0x00609acd ___uigesturerecognizerupdate_block_invoke + 57 26 uikit 0x00609a4e _uigesturerecognizerremoveobjectsfromarrayandapplyblocks + 317 27 uikit 0x00600148 _uigesturerecognizerupdate + 199 28 uikit 0x002cc19a -[uiwindow _sendgesturesforevent:] + 1291 29 uikit 0x002cd0ba -[uiwindow sendevent:] + 1030 30 uikit 0x002a0e86 -[uiapplication sendevent:] + 242 31 uikit 0x0028b18f _uiapplicationhandleeventqueue + 11421 32 corefoundation 0x0172583f __cfrunloop_is_calling_out_to_a_source0_perform_function__ + 15 33 corefoundation 0x017251cb __cfrunloopdosources0 + 235 34 corefoundation 0x0174229e __cfrunlooprun + 910 35 corefoundation 0x01741ac3 cfrunlooprunspecific + 467 36 corefoundation 0x017418db cfrunloopruninmode + 123 37 graphicsservices 0x03aa39e2 gseventrunmodal + 192 38 graphicsservices 0x03aa3809 gseventrun + 104 39 uikit 0x0028dd3b uiapplicationmain + 1225 40 bjjdrillingapppro 0x0001bf0d main + 141 41 libdyld.dylib 0x0213c70d start + 1 42 ??? 0x00000001 0x0 + 1 )
and after looking @ code keyboard did show , hide methods wondering if maybe doing wrong there:
this in viewdidload:
[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboarddidshow) name:uikeyboardwillshownotification object:nil]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboarddidhide) name:uikeyboardwillhidenotification object:nil];
and these selectors:
- (void)keyboarddidhide { if(keyboardshown) { cgrect r = self.scrollview.frame; r.size.height += 216; self.scrollview.frame = r; keyboardshown = no; } } - (void)keyboarddidshow { if(!keyboardshown) { cgrect r = self.scrollview.frame; self.scrollview.contentsize = self.scrollview.frame.size; r.size.height -= 216; self.scrollview.frame = r; keyboardshown = yes; } }
you don't need gesture recognizer.
scrollviews have keyboarddismissmode
property. set uiscrollviewkeyboarddismissmodeondrag
or uiscrollviewkeyboarddismissmodeinteractive
, set go.
Comments
Post a Comment