0

我想在 iPhone 的子视图上显示 gif 图像。示例代码 glgif 在控制器的根视图上显示 gif 图像,但是当我进行以下修改时,应用程序会崩溃:

IBOutlet UIView *gifView;  // gifView is added as a subview of controller's root view

//PlayerView *plView = (PlayerView *)self.view;
PlayerView *plView = (PlayerView *)gifView;

// Load test.gif VideoSource
NSString *str = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"gif"];
FILE *fp = fopen([str UTF8String], "r");
VideoSource *src = VideoSource_init(fp, VIDEOSOURCE_FILE);
src->writeable = false;

// Init video using VideoSource
Video *vid = [[GifVideo alloc] initWithSource:src inContext:[plView context]];
VideoSource_release(src);

// Start if loaded
if (vid) {
    [plView startAnimation:vid];
    [vid release];
    return;
}

// Cleanup if failed
fclose(fp);

现在应用程序在这一行崩溃: Video *vid = [[GifVideo alloc] initWithSource:src inContext:[plView context]];并显示错误消息:-[UIView context]: unrecognized selector sent to instance。关于如何将 plView 正确添加到子视图的任何想法?

4

1 回答 1

0

看起来 plView 是 UIView,而不是 PlayerView,并且没有名为“context”的方法。

于 2010-06-11T02:19:55.063 回答