讓我們來討論第一個項目,時間軸控制。
這將是一系列自定義視圖,一個用於標註(1個三角形和一個帶有文本的矩形按鈕),一個時間軸(一行和一組點陣)以及一個包裝視圖,可以接受在時間線上繪製的名稱列表。
每個視圖將負責繪製自己。該視圖可以使用來自psd的拼接圖像,或實際繪製自己。就嘗試開發跨平臺代碼而言,它可以完成,但這通常意味着您必須在每個平臺上接受許多妥協。
作爲一種替代方案,您可以爲您的界面使用html5視圖,並使用本地代碼來連接業務邏輯。
下面是使用JavaScript畫布創建標註的粗略示例。 http://jsfiddle.net/5ZMn9/7/
function Callout() {
this.x = 0;
this.y = 0;
this.width = 0;
this.height = 0;
this.position = 1;
this.name = "";
}
Callout.prototype = {
draw: function(canvas) {
var callout = this;
canvas.drawPolygon({
fillStyle: 'blue',
x: callout.x, y: callout.y-12+callout.position*25,
radius: 5,
sides: 3,
rotate: (callout.position)*180
});
canvas.drawRect({
fillStyle: 'blue',
x: callout.x, y: callout.y,
width: 50,
height: 20
});
canvas.drawText({
fillStyle: '#fff',
x: callout.x, y: callout.y+2,
fontSize: 8,
fontFamily: 'Verdana, sans-serif',
text: callout.name
});
}
};
function Timeline() {
this.x = 0;
this.y = 0;
this.length = 0;
this.stops = 0;
}
Timeline.prototype = {
draw: function(canvas) {
var timeline = this;
canvas.drawLine({
strokeStyle: '#960',
strokeWidth: 2,
x1: timeline.x, y1: timeline.y,
x2: timeline.x+timeline.length, y2: timeline.y
});
for (var i=0; i < this.stops; i++) {
canvas.drawEllipse({
fillStyle: '#c90',
x: timeline.x+30+50*i, y: timeline.y,
width: 8, height: 8
});
}
}
};
function Wrapper() {
this.names = [];
this.height = 300;
this.width = 600;
}
Wrapper.prototype = {
draw: function(canvas) {
$(canvas).clearCanvas();
var timeline = new Timeline();
timeline.x = 0;
timeline.y = 45;
timeline.length = this.names.length*50+10;
timeline.stops = this.names.length;
timeline.draw(canvas);
for (var i = 0; i<this.names.length; i++) {
var callout = new Callout();
callout.x = i*50+30;
callout.y = i%2*50+20;
callout.position = 1-i%2;
callout.name = this.names[i];
callout.width=90;
callout.draw(canvas);
}
}
};
var wrapper = new Wrapper();
wrapper.names = ["One","Two","Three","Four","Five"];
wrapper.draw($('canvas'));
來源
2014-03-25 00:21:53
B2K
有趣的,你想我建議一個UI框架?或者你問我「如何創建UI框架」?請清楚你完全想要什麼。 – ArunRaj
使用[tag:node.js]。 'npm install phaser'並將其設置爲眩暈。 –