Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

zyggiepyggie

macrumors member
Original poster
Apr 9, 2010
32
0
Hi,

I'm currently learning Objective-C from barely no programming experience in the past, it's going pretty well.

I'm struggling with a piece of code, and would appreciate if someone could help me out? The app is from a tutorial that I am adapting (obviously not going to put the app on the app store, just using it to learn).

Is there anyway of using setFrame on an array of images?

Here's the code:

Code:
-(void)flyStance  {
    
    [self cleanStance];
    NSArray *imageArray = [[NSArray alloc] initWithObjects:
                           [UIImage imageNamed:@"owl2.png"], nil];
                            
    self.owl.animationImages = imageArray;
    self.owl.animationDuration = 0.3;
    self.owl.contentMode = UIViewContentModeBottomLeft;
    [self.view addSubview:self.owl];
    [self.owl startAnimating];

The method is activated by a button press but the image appears in the wrong position and scaled up. I plan to add more images to the array in the near future by the way.

Any help would be appreciated.

Thanks!
 

seepel

macrumors 6502
Dec 22, 2009
471
1
It might help to know your end goal. You want your image to animate with the set of UIImages you've provided, that is pretty obvious. What do you expect setFrame to do? I'm not familiar with using UIImage's animationImages. But UIView's are pretty tightly coupled to CoreAnimation and you can get nice animations out of that (including setFrame). So if for example you wanted to have your UIImageView grow and move around you could do this.

Code:
[UIView animateWithDuration:0.5 animations:^( ) {
   imageView.frame = CGRectMake(x,y,width,height);
}];

And your imageView will animate from its current frame, to the specified frame in half a second. You can look at the documentation for more info and more details on the animations you can do with this technique.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html
 

zyggiepyggie

macrumors member
Original poster
Apr 9, 2010
32
0
It might help to know your end goal. You want your image to animate with the set of UIImages you've provided, that is pretty obvious. What do you expect setFrame to do? I'm not familiar with using UIImage's animationImages. But UIView's are pretty tightly coupled to CoreAnimation and you can get nice animations out of that (including setFrame). So if for example you wanted to have your UIImageView grow and move around you could do this.

Code:
[UIView animateWithDuration:0.5 animations:^( ) {
   imageView.frame = CGRectMake(x,y,width,height);
}];

And your imageView will animate from its current frame, to the specified frame in half a second. You can look at the documentation for more info and more details on the animations you can do with this technique.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html


I used setFrame earlier in the code to position an image where I want it on the screen. The animation is a bird with its wings down, you press the button and it's wings flap up and back down... simple, right?

When the above method runs instead of the image animating where I want it, it appears to the right of the screen - I need a way to reposition it where it should be...

I hope that makes sense?

I'll try getting it to work as you have mentioned above.

Thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.