0

I want to set a position of an object programmatically. For this I do:

youtubeIco.frame.origin.y = 100

but nothing. It doesn't change coordinates at all. What is the problem?

And a second question:

when I set in the XCode constraints of webView(for ex: 10(top, left, right, bottom) it disappears. But when I do not set constraints for it, it appears. What is the problem?

I want like this:

enter image description here

Orkhan Alizade
  • 7,379
  • 14
  • 40
  • 79
  • 2
    Rather than manipulating the frame you should manipulate the constraint. You can create an IBOutlet for the constraint to make this easier – Paulw11 Apr 29 '15 at 10:22

2 Answers2

5

You need to set full frame like,

youtubeIco.frame = CGRectMake(youtubeIco.frame.origin.x, 100,youtubeIco.frame.size.width,youtubeIco.frame.size.height)

Only y-axis change will not do anything to it, you have to provide full frame for that. or set centre, or offset.

Viral Savaj
  • 3,379
  • 1
  • 26
  • 39
1

With AutoLayout you can't change a view's frame directly. The constraint puts the object right back where it was.

Instead, you should add constraints that position your views and add IBOutlets to those constraints. Then you use the outlet(s) to change the constant value of the constraint, and the constraint moves your view objects for you. (In this context anything you can display on the screen is a view {a descendant of UIView} including buttons.)

Duncan C
  • 128,072
  • 22
  • 173
  • 272