iOS: Autosizing not working on UIImageView

只谈情不闲聊 提交于 2019-12-12 17:31:00

问题


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')

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):

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:

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:

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:


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;

        }];
}


来源:https://stackoverflow.com/questions/25520653/ios-autosizing-not-working-on-uiimageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!