2

I am making a very simple app to learn Objective-C and Xcode. The app has an UIButton and a UIImageView. When the user taps the button the image moves down in a diagonal motion from right to left and when it reaches a certain point in the screen it regenerates back to do the same all over again as shown in the image below:

(Using an 'if statement')

enter image description here

When I open the iOS simulator using iPhone Retina (4-inch) it works perfectly fine. The problem is when I open the simulator using iPhone Retina (3.5 inch):

enter image description here

It loads the image and everything seems fine, I press the button until the image reaches point B but when it regenerates back this is what happens:

enter image description here

The image moved down.I have no clue why it does this. I been searching for an answer all day long but nothing seems to work. I have the Auto Layout box unchecked and autosizing like this:

enter image description here

Here is the code:

File.h

{
    IBOutlet UIImageView *imageOne;

}

-(IBAction)Button:(id)sender;

@end

File.m

-(IBAction)Button:(id)sender{    

//ImageOne moving down and reappearing

[UIView animateWithDuration:0.1f
                 animations:^{

                     imageOne.center = CGPointMake(imageOne.center.x -44, imageOne.center.y +41);

                 }];

if (imageOne.center.x < -28) {
    imageOne.center = CGPointMake(368,487);

    }
}

Any help would be greatly appreciated

Thank you in advance!!!

1 Answers1

0

Try this:

-(IBAction)Button:(id)sender{    

   CGPoint startingPoint = CGPointMake(startingXPoint, startingYPoint);
   CGPoint destinationPoint = CGPointMake(destinationXPoint, destinationYPoint);
   imageOne.center = startingPoint;



   [UIView animateWithDuration:0.5f  animations:^{

            imageOne.center = destinationPoint;

        } completion:^(BOOL finished){

            imageOne.center = startingPoint;

        }];
}
Zigglzworth
  • 6,645
  • 9
  • 68
  • 107
  • Unfortunately it didn't work... My problem is that when the image reaches point B the setting that i have for autosizing doesn't work anymore. – Luis Villavicencio Aug 27 '14 at 10:55
  • Is there a way to set an if statement that says: if (is iPhone (3.5 inch)) { imageOne.center = CGPointMake(other_x_value, other_y_value } else { imageOne.center =CGPointMake (368,487); – Luis Villavicencio Aug 27 '14 at 11:02
  • setting that you have for autosizing? not sure what you mean. This works for me so something in your settings is causing the issue – Zigglzworth Aug 27 '14 at 13:02