gpt4 book ai didi

iphone - 完成后从 viewDidLoad 中移除动画

转载 作者:行者123 更新时间:2023-11-29 13:49:49 24 4
gpt4 key购买 nike

我有一个动画(图像数组),我将其放入 viewDidLoad 中,因为我希望它在开始后立即播放。在 viewDidLoad 中的动画之后,我还在 UIWebView 中显示了一个我想保留的 webview。动画播放(出于某种原因不是我创建的 UIImage )但完成后我无法摆脱它。我试过放入一个计时器并从 super View 中删除动画,但它没有删除它,而是退出了应用程序并返回到主页。

-(void)viewDidLoad
{
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];

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

[self.view addSubview:animation];

//set timer to remove animation from view
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval: 3
target: self
selector: @selector(removeAnimation:)
userInfo: nil
repeats: NO];

//for loading the image at start up
NSString *urlAddress = @"http://projects.seng.uvic.ca/most_recent.php";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

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

//removes the animation from subview
- (void) method: (NSTimer*) theTimer
{
[animation release];
[animation removeFromSuperview];
}

最佳答案

看起来您选择的选择器 (removeAnimation:) 和您显示的方法 (method:) 的名称不同。

一个更简单的方法是做这样的事情:

-(void)viewDidLoad
{
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];

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

[self.view addSubview:animation];
[self performSelector:@selector(removeAnimation) withObject:nil afterDelay:8.0];


//for loading the image at start up
NSString *urlAddress = @"http://projects.seng.uvic.ca/most_recent.php";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

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

- (void)removeAnimation
{
[animation removeFromSuperview];
[animation release];
}

大家好,我是 Pandas 。

关于iphone - 完成后从 viewDidLoad 中移除动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5344355/

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