在 UIWebview 中添加一个 gif 视频文件
Add a gif video file in UIWebview
我要在 Objective-C 中的 UIWbeview
中添加 GIF 图片。问题是图像大小不适合屏幕,gif 视频上方的内容没有显示。如何调整图像大小并显示其上方的按钮。
我的代码是:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"back" ofType:@"gif"];
NSData *gif = [NSData dataWithContentsOfFile:filePath];
UIWebView *webViewBG = [[UIWebView alloc] initWithFrame:self.view.frame];
[webViewBG loadData:gif MIMEType:@"gif" textEncodingName:NULL baseURL:NULL];
webViewBG.userInteractionEnabled = NO;
webViewBG.scalesPageToFit=YES;
[self.view addSubview:webViewBG];
// Do any additional setup after loading the view.
}
您可以将代码移至 viewDidAppear
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"back" ofType:@"gif"];
NSData *gif = [NSData dataWithContentsOfFile:filePath];
UIWebView *webViewBG = [[UIWebView alloc] initWithFrame:self.view.frame];
[webViewBG loadData:gif MIMEType:@"image/gif" textEncodingName:@"UTF-8" baseURL:NULL];
webViewBG.userInteractionEnabled = NO;
webViewBG.scalesPageToFit=YES;
[self.view addSubview:webViewBG];
}
我要在 Objective-C 中的 UIWbeview
中添加 GIF 图片。问题是图像大小不适合屏幕,gif 视频上方的内容没有显示。如何调整图像大小并显示其上方的按钮。
我的代码是:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"back" ofType:@"gif"];
NSData *gif = [NSData dataWithContentsOfFile:filePath];
UIWebView *webViewBG = [[UIWebView alloc] initWithFrame:self.view.frame];
[webViewBG loadData:gif MIMEType:@"gif" textEncodingName:NULL baseURL:NULL];
webViewBG.userInteractionEnabled = NO;
webViewBG.scalesPageToFit=YES;
[self.view addSubview:webViewBG];
// Do any additional setup after loading the view.
}
您可以将代码移至 viewDidAppear
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"back" ofType:@"gif"];
NSData *gif = [NSData dataWithContentsOfFile:filePath];
UIWebView *webViewBG = [[UIWebView alloc] initWithFrame:self.view.frame];
[webViewBG loadData:gif MIMEType:@"image/gif" textEncodingName:@"UTF-8" baseURL:NULL];
webViewBG.userInteractionEnabled = NO;
webViewBG.scalesPageToFit=YES;
[self.view addSubview:webViewBG];
}