We have a View which displays different fields of the View:

UILabel UITextField UILabel UITextField 

And so on. I need to fill out a certain UITextField field (let's call it ShowTextField) under it another one that was previously hidden. Setting the hidden parameter to true / false, I know how to do it, but I need other fields (which were previously under ShowTextField) to go below ...

Quickly sketched jQuery code to make it clearer - http://jsfiddle.net/wfjuy75u/

Then I have under each other fields and text fields and I need to, when clicked (and ideally when filling in) a certain field, drop those below it even lower to fit the new one.

  • I assume that there is a typo in the question - UITextField and not UITextLabel - Max Mikheyenko
  • Yes, you are right, thank you) - DEM909

2 answers 2

Something I apparently did not understand the question. You need to change the frame all your views that are lower than necessary:

 let frame:CGRect = self.view.frame frame.origin.y += 30 // ну например 30. //правильнее будет использовать высоту скрытого поля self.view.frame = frame 

To show a new field when something is entered into the desired UITextField, you must declare your class as a delegate for that field text, and check the input of new characters in the textField(_:shouldChangeCharactersInRange:replacementString:) . when something is entered in the field you want, show the hidden field and move everything under it.

  • Thank! I will try - DEM909
  • Cannot move elements in this way. More precisely, on some screens they move, but on which they should appear - no. Maybe this is due to the fact that I have a constraint on the distance from the element (which is above)? Because when I write: print(MyLabel.frame) MyLabel.frame = CGRectMake(160, 200, 60, 40) print(MyLabel.frame) I get different values ​​(which were first, and then those that I indicated), but the position of the element on the screen does not change - DEM909
  • Then the answer HunTer255 should help. - Max Mikheyenko

It is probably better to use Autolayout in this case, place all UITextField and set constrains for them, for default hidden UITextField expose height 0 in the code when loading, and when entering text into the desired UITextField increase the height of the hidden element, even with animation. In this case, there will be no need to calculate the shift of other UITextField , everything will be done on the machine.

  • Could you tell me how all this is done? Or throw off the link to the article, otherwise I do not quite know how to work with Autolayout. - DEM909
  • I can’t tell, the tool is quite voluminous and you can’t tell about all the possibilities and subtleties. In Russian, I advise you to watch the lessons on youtube, from "Konstantin Kokorin". There are some good articles in English here: raywenderlich.com/50317/… - HunTeR255