2017-05-08 35 views
0

enter image description here在這裏輸入圖片描述,enter image description here。我在Objective-C的UIWbeview中添加了一個GIF圖像,問題是圖像尺寸不適合屏幕,並且沒有顯示gif視頻上方的內容。如何調整圖像大小並顯示上方的按鈕。在UIWebview中添加一個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. 
} 
+1

GIF是一個圖像,而不是視頻。你的問題不清楚,添加一些屏幕截圖,更多的描述。 – iphonic

+0

請分享VC的屏幕瀏覽 –

+0

https://medium.com/swift-programming?source=logo-lo_70f977b2b7e9---5396e0e8bc29。我遵循這個。 @iphonic –

回答

0

您可以將代碼移到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]; 
} 
+0

無法正常工作。 @Luan Tran –

+0

可以幫我嗎? @Luan Tran –

+0

當你使用'viewDidAppear'時,觸發器是否轉到那個函數? –