setFrame on NSArray?

Discussion in 'iOS Programming' started by zyggiepyggie, Mar 18, 2011.

  1. zyggiepyggie macrumors member

    zyggiepyggie

    Joined:
    Apr 9, 2010
    #1
    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!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    UIImages don't have frames. They are not views. So you can't call setFrame on a UIImage, let alone an array of them.
     
  3. seepel macrumors 6502

    seepel

    Joined:
    Dec 22, 2009
    #3
    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
     
  4. zyggiepyggie thread starter macrumors member

    zyggiepyggie

    Joined:
    Apr 9, 2010
    #4

    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.
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    I bet you called setFrame: on a UIImageView. This is totally different to a UIImage.
     

Share This Page