Objective c 使用WKWebView嵌入YouTube
我对MacOS Objective-C编码非常陌生。我知道在显示YouTube视频时有很多iOS解决方案,但我正在尝试使用MacOS和Objective C 到目前为止,我正在使用WKWebView显示url。这项工作很好,除了我更希望在窗口中全屏显示youtube视频(并且只显示视频,而不是整个youtube网页和视频) 我的解决方案是使用嵌入而不是直接urlObjective c 使用WKWebView嵌入YouTube,objective-c,xcode,macos,youtube,wkwebview,Objective C,Xcode,Macos,Youtube,Wkwebview,我对MacOS Objective-C编码非常陌生。我知道在显示YouTube视频时有很多iOS解决方案,但我正在尝试使用MacOS和Objective C 到目前为止,我正在使用WKWebView显示url。这项工作很好,除了我更希望在窗口中全屏显示youtube视频(并且只显示视频,而不是整个youtube网页和视频) 我的解决方案是使用嵌入而不是直接url NSURL *nsurl=[NSURL URLWithString:@"https://www.youtube.com/em
NSURL *nsurl=[NSURL URLWithString:@"https://www.youtube.com/embed/t168mpf0SxU"];
但是,我调整了窗口的大小。视频不会调整嵌入窗口的webview的大小。有没有一段代码是我缺少的?我的解决方案是首先设置自动调整遮罩大小的约束:
[webView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.webNSView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[webView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(webView)]];
[self.webNSView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[webView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(webView)]];
然后,要添加布局约束,请执行以下操作:
[webView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.webNSView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[webView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(webView)]];
[self.webNSView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[webView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(webView)]];
这似乎是在NSView中调整WKWebView的大小我的解决方案是首先设置自动调整掩码大小的约束:
[webView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.webNSView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[webView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(webView)]];
[self.webNSView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[webView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(webView)]];
然后,要添加布局约束,请执行以下操作:
[webView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.webNSView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[webView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(webView)]];
[self.webNSView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[webView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(webView)]];
这似乎可以在NSView中调整WKWebView的大小