Adding animation at start up using an array of images

那年仲夏 提交于 2020-01-24 15:13:14

问题


I'm new to iphone app development and I'm trying to add an image to the start of my app. I've created an array of images which when iterated should create an animation.

-(void)viewDidLoad
{

    animation = [[UIImageView alloc] init];
    animation.animationImages = [NSArray arrayWithObjects: 
                                                 [UIImage imageNamed:@"panda1.png"],                                  
                                                 [UIImage imageNamed:@"panda2.png"],                              
                                                 [UIImage imageNamed:@"panda3.png"], nil];

    animation.animationRepeatCount = 2;
    animation.animationDuration = 2;
    [animation startAnimating];

    [self.view addSubview:animation];

    [animation release];

    //for loading the webpage at start up

    NSString *urlAddress = @"http://projects.seng.uvic.ca/fatpanda/m/most_recent.php";
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    //load the request in the UIWebView
    [webView loadRequest:requestObj];   
}

The reason I release the animation at the end of this is because I'd like to remove the last image so I can replace it with a view of a website in a UIWebView and have that visible at the end. The code above compiles but when I run it no images appear but the website does.

Any help would be greatly appreciated.


回答1:


try this, i think your frame is ending up all zeros.

UIImage * first = [UIImage imageNamed:@"panda1.png"]
animation = [[UIImageView alloc] initWithImage:first];
animation.animationImages = [NSArray arrayWithObjects: 
                                             first,                                  
                                             [UIImage imageNamed:@"panda2.png"],                              
                                             [UIImage imageNamed:@"panda3.png"], nil];

Also... releasing the animaiton will not remove it from the superview. in fact calling addSubview will increase the reference count to the UIImageView and releasing it is the correct thing to do. When you want to to remove from the view it you will have to find it again in the list of subviews and either hide it or call removeFromSuperview.



来源:https://stackoverflow.com/questions/5317278/adding-animation-at-start-up-using-an-array-of-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!