我正在使用TVML为TVOS App开发模板。该应用程序使用MenuBar。但只有当用户单击Home / Back按钮时,此MenuBar才会打开。我只是想通过向上滑动来实现它。喜欢它在TVOS的Youtube应用程序中。 index.xml的代码(MenuBar所在的位置):
<?xml version="1.0" encoding="UTF-8" ?>
<document>
<menuBarTemplate>
<menuBar>
<menuItem documentURL="/templates/MyProject/Events.xml" autoHighlight="true">
<title>Events</title>
</menuItem>
<menuItem documentURL="/templates/MyProject/News.xml">
<title>News</title>
</menuItem>
<menuItem documentURL="/templates/MyProject/Programs.xml">
<title>Programs and Courses</title>
</menuItem>
<menuItem documentURL="/templates/MyProject/Settings.xml">
<title>Settings</title>
</menuItem>
</menuBar>
</menuBarTemplate>
</document>
答案 0 :(得分:2)
您需要向application.js添加功能,例如(来自https://developer.apple.com/library/content/documentation/TVMLKitJS/Conceptual/TVMLProgrammingGuide/AddingaMenuBar.html):
var baseURL;
function loadingTemplate() {
var loadingDoc = "<document><loadingTemplate><activityIndicator>
<text>Loading Page</text></activityIndicator></loadingTemplate>
</document>";
var parser = new DOMParser();
var parsedTemplate = parser.parseFromString(loadingDoc, "application/xml");
return parsedTemplate;
}
function alertTemplate() {
var alertDoc = "<document><alertTemplate><title>Error</title>
<description>Page failed to load</description></alertTemplate></document>";
var parser = new DOMParser();
var parsedTemplate = parser.parseFromString(alertDoc,
"application/xml");
return parsedTemplate;
}
function loadAndPushDocument(url) {
var loadingDocument = loadingTemplate();
navigationDocument.pushDocument(loadingDocument);
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.onreadystatechange = function() {
if (request.readyState != 4) {
return;
}
if (request.status == 200) {
var document = request.responseXML;
document.addEventListener("select", handleSelectEvent);
navigationDocument.replaceDocument(document, loadingDocument)
}
else {
navigationDocument.popDocument();
var alertDocument = alertTemplate();
navigationDocument.presentModal(alertDocument);
}
};
request.send();
}
function updateMenuItem(menuItem, url) {
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.onreadystatechange = function() {
if (request.status == 200) {
var document = request.responseXML;
document.addEventListener("select", handleSelectEvent);
var menuItemDocument =
menuItem.parentNode.getFeature("MenuBarDocument");
menuItemDocument.setDocument(document, menuItem)
}
};
request.send();
}
function handleSelectEvent(event) {
var selectedElement = event.target;
var targetURL = selectedElement.getAttribute("selectTargetURL");
if (!targetURL) {
return;
}
targetURL = baseURL + targetURL;
if (selectedElement.tagName == "menuItem") {
updateMenuItem(selectedElement, targetURL);
}
else {
loadAndPushDocument(targetURL);
}
}
App.onLaunch = function(options) {
baseURL = options.BASEURL;
var startDocumentURL = baseURL + "templates/menuBar.xml";
loadAndPushDocument(startDocumentURL)
}