How to create Animation Graphic for Iphone?

Discussion in 'iPhone/iPad Programming' started by lamfan, Aug 4, 2008.

  1. macrumors newbie

    Joined:
    Aug 4, 2008
    Messages:
    6
    #1
    Is there any framework can work on it?

    I had thinking about using NSTime to set up loading different UIViewImage in every second,

    I don't know is that the right way to create animation graphic for iphone.

    Any suggestion?
     
  2. macrumors member

    Joined:
    Jul 9, 2008
    Messages:
    42
    #2
    UIImageView

    Use UIImageView for simple animations.

    You set the animationImages to an NSArray of UIImage*. Then you set the animationDuration and animationRepeatCount on your UIImageView. Finally, you need to call startAnimating on the UIImageView. That will cause the animation to cycle through your images animationRepeatCount times, or until you call stopAnimating.

    That's a very high-level, simple view of how to start out with animation on the iPhone. You can do more interesting things with layers and so forth, but that's a bugger question...;)
     
  3. macrumors regular

    Joined:
    Jul 28, 2008
    Messages:
    126
    #3
    animation not working on the simulator

    Hi col i tried doing the following

    NSArray *images = [NSArray arrayWithObjects:mad:"groundhog2.jpg",@"noframes.gif"];
    UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 300.0)];
    [imageView setAnimationImages:images];
    [imageView setAnimationRepeatCount:2];
    //imageView.image = [UIImage imageNamed:mad:"noframes.gif"];//img;
    imageView.center = self.center;
    self.picView = imageView;

    [imageView release];
    [self.picView startAnimating];
    [self addSubview:picView];

    it crashes, why so ?

    should it work on simulator ?

    Jagat
     
  4. Moderator

    robbieduncan

    Staff Member

    Joined:
    Jul 24, 2002
    Messages:
    24,480
    Location:
    London
    #4
    I imagine it crashes because you've set the images to an array of strings, not an array of images.
     
  5. macrumors regular

    Joined:
    Jul 28, 2008
    Messages:
    126
    #5
    thanks but ...

    i tried the folowing modified code, still it crashes

    UIImage* img1 = [UIImage imageNamed:mad:"groundhog2.jpg"];
    UIImage* img2 = [UIImage imageNamed:mad:"noframes.gif"];

    NSArray *images = [NSArray arrayWithObjects:img1,img2];
    UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 300.0)];
    [imageView setAnimationImages:images];
    [imageView setAnimationRepeatCount:2];
    //imageView.image = [UIImage imageNamed:mad:"noframes.gif"];//img;
    imageView.center = self.center;
    self.picView = imageView;
    //[imageView startAnimating];
    [imageView release];
    [self.picView startAnimating];
    [self addSubview:picView];
     
  6. Moderator

    robbieduncan

    Staff Member

    Joined:
    Jul 24, 2002
    Messages:
    24,480
    Location:
    London
    #6
    Well now you are abusing NSArray arrayWithObjects:. As per the documentation (which I would expect you to use to solve these problems) you must terminate the list of objects with nil.
     
  7. macrumors regular

    Joined:
    Jul 28, 2008
    Messages:
    126
    #7
    thanks a lot

    Thanks a lot. how could I do this.

    anyway, it is working now, though one thing is after animation finished the view becomes black. how would i be animating infinitely ? or else after count finishes, how can i stop on the ending image ?

    moreover I am doing this in initframe now. I want to do it on tap on the static image. means, first a static image will display, when i click on that the animation will play and go back to previous static image.

    please guide me doing that

    thanks and regards

    Jagat
     
  8. Moderator

    robbieduncan

    Staff Member

    Joined:
    Jul 24, 2002
    Messages:
    24,480
    Location:
    London
    #8
    Please read the documentation. We are not here to research the answers to basic questions clearly covered in the documentation for you. If you can't use the documentation you shouldn't be programming for the platform.
     

Share This Page