gpt4 book ai didi

iphone - 使用图像数组在启动时添加动画

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:57:20 25 4
gpt4 key购买 nike

我是 iPhone 应用程序开发的新手,我正在尝试将图像添加到我的应用程序的开头。我创建了一个图像数组,迭代时应该创建一个动画。

-(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];
}

我在最后发布动画的原因是因为我想删除最后一张图片,这样我就可以用 UIWebView 中的网站 View 替换它,并在最后显示它。上面的代码可以编译,但是当我运行它时没有图像出现,但是网站出现了。

如有任何帮助,我们将不胜感激。

最佳答案

试试这个,我认为你的帧结束时全为零。

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];

还有...释放动画不会将其从 super View 中删除。事实上,调用 addSubview 会增加对 UIImageView 的引用计数,释放它是正确的做法。当你想从 View 中删除它时,你必须在 subview 列表中再次找到它并隐藏它或调用 removeFromSuperview。

关于iphone - 使用图像数组在启动时添加动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5317278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com