简体   繁体   中英

UIView animate frame of ImageView

I'm trying to add an animation to a UIImageView when a button is tapped. When the button is tapped I want the imageView to move to the right at the same time as it is increasing in size. I have tried this code, but the imageView aren't animation correct.

- (IBAction)bA:(id)sender {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDuration:0.5];
    CGRect frame = imageView.frame;
    frame.origin.x = frame.origin.x + 30;
    frame.size.hight = frame.size.hight + 20;
    frame.size.width = frame.size.width + 20;
    imageView.frame = frame;
    [UIView commitAnimations];
}

This code makes the imageView move little to the right, then back again. Wierd behavior, what should I do to animate both size and origin at the same time?

The problem is that you've got Autolayout turned on. With Autolayout, you cannot change the frame of something, because layout comes along and changes it back again.

Either turn Autolayout off, or else animate by changing the constraints of this view instead of its frame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM