Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用图像阵列在启动时添加动画_Iphone_Objective C_Ios_Animation - Fatal编程技术网

Iphone 使用图像阵列在启动时添加动画

Iphone 使用图像阵列在启动时添加动画,iphone,objective-c,ios,animation,Iphone,Objective C,Ios,Animation,我是iphone应用程序开发新手,我正在尝试在应用程序的开头添加一个图像。我已经创建了一个图像数组,当迭代时应该会创建一个动画 -(void)viewDidLoad { animation = [[UIImageView alloc] init]; animation.animationImages = [NSArray arrayWithObjects: [UIImage im

我是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中的网站视图替换它,并在最后显示它。上面的代码可以编译,但当我运行它时,没有图像出现,但网站会出现


任何帮助都将不胜感激。

试试这个,我想你的帧最终都是零

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];
还有。。。
释放动画不会将其从superview中删除。事实上,调用addSubview将增加对UIImageView的引用计数,释放它是正确的做法。当您想从视图中删除它时,您必须在子视图列表中再次找到它,并将其隐藏或调用removeFromSuperview。

谢谢您的帮助。但我在删除它时遇到了问题。我试过[从SuperView删除annimation];和annimation.hidden=是;在函数的末尾((我还将[animation release];移到了末尾),它们导致动画根本不显示。我甚至尝试在重新移动它们之前进行睡眠。睡眠没有帮助。将其安排在NSTimer上。我创建了一个计时器计时器=[NSTimer scheduledTimerWithTimeInterval:3目标:自选择器:@selector(removeAnimation:)userInfo:nil repeats:NO];然后我的函数removeAnimation有[animation release];[animation removeFromSuperview];它似乎删除了动画,但同时退出了应用程序。