0

I'm working on an old project of mine with a xib file in it. I have a button that changes the position of an UIImageview to 0,0, but it doesn't work and the label stays at its initial position. When I create new project with the exact same code expect it contains a mainStoryboard.Storyboard it works fine. I suppose it has something to do with the xib file and files owner.

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)Action1:(id)sender {
    imageview.center = CGPointMake(0, 0);
}
Freddy
  • 810
  • 1
  • 9
  • 19
  • You say `UIImageView`'s center but I only see a `UILabel`'s center being called...? – JMarsh Mar 04 '14 at 18:44
  • label1 is imageView ? as @JMarsh asked already , where is UIImageView ? please post a proper question. – Pawan Rai Mar 04 '14 at 18:58
  • Ohh sorry i edited it. I posted wrong code, but its still the same problem with labels and all other UI-elements. ;) – Freddy Mar 04 '14 at 19:01
  • Are you using `auto layout` ? If so, note that changing the frame may not have any effect... you'd need to change the constraints on the view. – JRG-Developer Mar 04 '14 at 19:02
  • Im not used to working with Xib files since i have only programmed for around 1 month. If you could explain abit more in detail that would be nice. And yes, I'm using auto-layout. – Freddy Mar 04 '14 at 19:06
  • Turning it of fixed it! now my question is what do auto layout do and when should i use it? – Freddy Mar 04 '14 at 19:09
  • 1
    Glad you got it working now, but you should post a new question (or actually, look for existing questions, which probably cover your questions) for the "What does auto layout do and when should you use it" part. For example, you might check out: http://stackoverflow.com/questions/18739033/ios-autolayout-vs-springs-struts – Aaron Golden Mar 04 '14 at 19:18

1 Answers1

0

If you're using auto layout, changing the frame may not have any effect.

Instead, you need to change the constraints on the view.

You can find a written tutorial on auto layout on Ray Wenderlich's site here or a video tutorial here.

JRG-Developer
  • 12,454
  • 8
  • 55
  • 81