How to add a custom animation property to a subclass of UIImageView?

I have a class that I have subclassed from UIImageView. An instance of this class is then added as a subordinate to the root class of my application. Now I can animate its properties, for example setFrame:

[UIView beginAnimations:nil context:nil]; ... [myImageView setFrame:someFrameCreatedInCode]; ... [UIView commitAnimations]; 

This takes the current frame as its initial state and interpolates the image animation (it just moves from left to right). This part works great.

What I would like to do next, I want to add a property to my class, say, an integer type. And I want this property to indicate the image number (its name is formatted) and later create a frame animation. This seems to be a good way to create an animation, because I can specify a β€œcurve” to affect the animation time:

 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 

How to implement my own property that can be revived?

Thanks in advance!

Update: in case someone needs it, I found these tutorials on the Internet: blog post , example .

+4
source share
1 answer

You will probably want to use UIView animation along with UIImageView animated images.

If you use this code:

 colors = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"red_select1.png"], [UIImage imageNamed:@"red_select2.png"], [UIImage imageNamed:@"red_select3.png"], [UIImage imageNamed:@"red_select4.png"], [UIImage imageNamed:@"red_select5.png"], [UIImage imageNamed:@"red_select6.png"], [UIImage imageNamed:@"red_select7.png"], [UIImage imageNamed:@"red_select8.png"],nil]; animationView = [[UIImageView alloc] initWithFrame:rect]; animationView.animationImages = colors; animationView.animationDuration = 1.0; animationView.animationRepeatCount = 0; // loop [animationView startAnimating]; 

I think the only problem will be the synchronization of the two animations ...

0
source

All Articles