Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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 完成后从viewDidLoad中删除动画_Iphone_Objective C_Ios_Animation - Fatal编程技术网

Iphone 完成后从viewDidLoad中删除动画

Iphone 完成后从viewDidLoad中删除动画,iphone,objective-c,ios,animation,Iphone,Objective C,Ios,Animation,我有一个动画(一组图像),我把它放在viewDidLoad中,因为我希望它在启动后立即播放。在viewDidLoad中完成动画后,我还将在UIWebView中显示一个我希望保留的webview。动画播放(由于某种原因不是我创建的UIImage),但完成后我无法将其删除。我试着在superview中加入一个计时器并移除动画,但它没有移除,而是退出应用程序并返回主页 -(void)viewDidLoad { UIImage *first = [UIImage imageNamed:@"pan

我有一个动画(一组图像),我把它放在viewDidLoad中,因为我希望它在启动后立即播放。在viewDidLoad中完成动画后,我还将在UIWebView中显示一个我希望保留的webview。动画播放(由于某种原因不是我创建的UIImage),但完成后我无法将其删除。我试着在superview中加入一个计时器并移除动画,但它没有移除,而是退出应用程序并返回主页

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


看起来您正在选择的选择器(
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];
}

您好,我是熊猫。

看起来您选择的选择器(
删除动画:
)和您显示的方法(
方法:
)的名称不同

更简单的方法是这样做:

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

你好,我是熊猫。

我不认为UIImageView在动画停止时提供代理回调

因此,如果您使用以下提问方式:

这也消除了对计时器的需要


最后,viewDidLoad至少被记录为用于设置数据模型和视图的地方,因为它不能保证在您想要设置动画的时候被调用。我会使用“viewWillAppear”或“viewDidAppear”来设置动画。

我不认为UIImageView在动画停止时提供代理回调

因此,如果您使用以下提问方式:

这也消除了对计时器的需要


最后,viewDidLoad至少被记录为用于设置数据模型和视图的地方,因为它不能保证在您想要设置动画的时候被调用。我会使用“viewWillAppear”或“viewDidAppear”来制作动画。

oops完全没有注意到缺少的函数名(仍然习惯于此mac键盘:()添加函数名修复了我的问题。oops完全没有注意到缺少的函数名(仍然习惯于此mac键盘:()添加函数名修复了我的问题。