1

I am using Xcode to try to change my images position randomly every time a button is pushed but for some reason, the image only moves once in a while when the button is pushed even though I know it received the button's IBAction because the NSLog in the IBAction displayed in the console, I have tried it two ways and both methods only worked sporadically

Method 1:

ranX = arc4random() %320;
ranY = arc4random() %480;
myImage.center = CGPointMake(ranX, ranY);

Method 2:

myImage.center = CGPointMake(arc4random() %320, arc4random() %480);

One more thing: every time it does work, the next IBAction to run puts it right back into its original position.

More information that might be pertinent I don't know, I do not have size classes enabled, it is triggered by touch up inside. I also DID make all the RNGs arc4random_uniform. The problem is fixed, just deselect auto layout.

jose
  • 11
  • 9

1 Answers1

0

What control event did you add to your button? Since you stated it moves every once in a while, you might have done the wrong event. Try UIControlEventTouchUpInside So,

[myButton addTarget:self action:@selector(moveImage) forControlEvents:UIControlEventTouchUpInside];

You're using a storyboard I see, Make sure that the send event for the button is "Touch Up Inside". Click on the button, go to the Connections Inspector and double check this.

SpencerBaker
  • 373
  • 2
  • 6