UIWebView content size in iOS 8

I am trying to display some content in a web view that is smaller than the screen. This works in iOS 7, but in iOS 8, the web view seems to automatically set the size of the content of the web view to screen size. How can I convince UIWebViewusing view size for content size in iOS 8?

I created a minimal example that illustrates the problem. Starting with the one-time Xcode iPad template, I’ve added a web view that is 480 pixels high and 320 pixels wide, centered in the parent view. I connected this to the output webViewin an existing view controller. Then I added the code -viewDidLoadto upload the .mp4 video to the web view. Here is the full code:

@interface ViewController ()

@property IBOutlet UIWebView *webView;

@end

NSString *const videoURL = @"https://dl.dropboxusercontent.com/u/29161243/Mahalo%2520Surf%2520Eco%2520Festival%25202014%2520-%2520Day%25204-SD.mp4";

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *url = [NSURL URLWithString:videoURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end

iOS 7 , . :

iOS7 correctly displays the content

iOS 8, , ; , , -:

iOS8 enlarges the content

iOS 7 iOS 8? -?

iOS 7 UIWebView (, HTML-) , , -. , - , -, , .

+4
2

viewDidLoad :

- (void)viewDidLoad {
    [super viewDidLoad];
    self.webView.mediaPlaybackRequiresUserAction = NO;
    NSString *videoHTML= [NSString stringWithFormat: @"<style type='text/css'>body { margin:0;background-color:black}</style><video width='%f' height='%f' frameborder='0' controls autoplay><source src=\"%@\" type=\"video/mp4\"></video><meta name='viewport' content='width=device-width, initial-scale=1,user-scalable=no,minimum-scale=1.0, maximum-scale=1.0'>", self.webView.frame.size.width, self.webView.frame.size.height,videoURL];
    [self.webView loadHTMLString:videoHTML baseURL:nil];
}

html , :

<meta name='viewport' content='width=device-width, initial-scale=1,user-scalable=no,minimum-scale=1.0, maximum-scale=1.0'> 

vs :

<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">

, iOS8, . , .

: https://developer.apple.com/library/IOS/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html

, !

+3

, - , - wAny | hAny size .

0

All Articles