您的位置:首页 > 产品设计 > UI/UE

UITextView keyboard

2015-08-29 22:27 218 查看


from:http://inessential.com/2014/01/07/uitextview_scroll-to-typing_bug


UITextViewScroll-to-TypingBug

AsI’vesaidmanytimes,I’mahugefanofText
Kit.It’sabigdealforVesper.Amongotherthings,itletsusdobolding/un-boldinginawaythatdidn’tworkreliablyorefficientlyiniOS6.

ButwithTextKitcameanewUITextView.TheoldonewasbasedonWebView,andthisoneisn’t.Thatmakesita1.0versionofUITextView,sinceit’sanewthing.Andithassomebugs.
(Notsurprisinglyfora1.0.)

I’vebeentryingtofigureoutwork-aroundsforthese.I’mmakingprogress.


Settheframe,notthecontentInset

PeopleWhoKnow(tm)(GregPierce,forone)haveadvisedmenottosetthecontentInsetoftheUITextViewwhenthekeyboardappearsanddisappears.Insteadchangetheframe.Inmytestingthismakesabigdifference.

Itmeansyoudon’tgettheblurred-outUITextViewunderneaththekeyboard,whichistoobad,butthattrade-offiseasytolivewith.


Scrollingtoshowtyping

Ihavethisalmostworking.LikeabottleofwineIjustcan’tmanagetoun-cork.

FromGregPierce(again),authorofDrafts,Ihavethiscode:

-(void)textViewDid​ChangeSelection:​(UITextView*)textView{




[textViewlayoutIfNeeded];




CGRectcaretRect=[textViewcaretRectForPosition:​textView.selectedTextRange.end];


NSLog(@"y%f",caretRect.origin.y);


caretRect.size.height+=textView.textContainerInset.bottom;




[textViewscrollRectToVisible:caretRectanimated:NO];


}


Youcandownloadasuper-simplesampleprojectwiththiscode.

Theoneplaceitfails:

Tapattheendofthetext.
TapReturn.

Thecaretishidden.Typeanyotherkeyanditun-hides.ButIreally,reallywantthecarettobenothiddenrightthen.

Ifyoulookintheconsoleyou’llnotethat
caretRect.origin.y
isjustplainincorrectwhenyoutapReturn.

YoucantapReturnagainandthenbackspaceandseethesamething—onlycaretRect.origin.ywillbewronginadifferentdirection.

Soclose.Icanalmosttastethewine.Ifyouhaveanyideas,pleaseletmeknow.I’vetriedabunchofthingsandI’mwillingto
trymore.

07Jan2014
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: