In Swift2.0, the use of Uitextfile and Uitextview in general and in OC is the same, today just give you a piece of code, and then say Uitextview inside the cursor position problem. Let's look at the simple code they're using.
Func Creatuiciew () { // TextView let textview:uitextview = Uitextview (Frame:cgrectmake (10, 100, 200, ) textview.layer.borderWidth = 1 textview.layer.borderColor = Uicolor.purplecolor (). Cgcolor textview.textcolor=uicolor.redcolor () Textview.font = Uifont. Systemfontofsize . Addsubview (TextView) // automatically adapts to the insertion point of the scrollerview. self.automaticallyadjustsscrollviewinsets = false; textfile let Textfile:uitextfield = Uitextfield (Frame:cgrectmake (ten, $, +)) Textfile.layer.borderWidth = 1 textfile.layer.borderColor = Uicolor.purplecolor (). Cgcolor self.view. Addsubview (textfile) } //touch gesture, recycle keyboard. override func Touchesbegan (touches:set<uitouch>, withevent event:uievent?) { Self.view. Endediting (True) }
Mainly say this self.automaticallyadjustsscrollviewinsets = False after this property automaticallyadjustsscrollviewinsets, Look at the simple literal meaning is actually enough, automatically adapts to the ScrollView insertion point. Here if you set it to true, it's insertion point you give to the Uinavigationcontroller to control, often there will be such a bizarre problem. But if you set it to false, it will give you control, and the insertion point will be inserted in the position you initialized! Uitextview In fact is also inherited and Uiscrollview, so he can control the Uitextview cursor input position.
Use of Swift2.0 Uitextview and Uitextfile