Use a web mobile framework?

前端 未结 5 2064
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 14:47

I\'m currently on a new projet to realize an application for mobile. The client isn\'t decided and I\'ve to suggest several solutions. The compatibility with Android (versio

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 15:21

    Yes, you can do this in Titanium. A naive implementation is below, drafted and tested in 5 minutes.

    To give you an idea what it could look like, refer to the following. Then look at TiDraggable, by Pedro Enrique, if you want to enhance it to let the user drag around text or images relative to each other: https://github.com/pec1985/TiDraggable

    // This app consists of two visual parts: a canvas where the user does stuff,
    // and a save button in the bottom right.
    var win = Ti.UI.createWindow({
        backgroundColor: 'black'
    });
    
    // First, the canvas.
    var canvas = Ti.UI.createView({
        bottom: 50,
        backgroundColor: 'white'
    });
    // It has a scroll view so the user can...
    var scroll = Ti.UI.createScrollView({
        // ... zoom content in or out.
        maxZoomScale: 2, minZoomScale: 0.1,
        // .. and freely position the image.
        contentWidth: 1000, contentHeight: 1000
    });
    // Add the image to the middle of the scroll view.
    scroll.add(Ti.UI.createImageView({
        image: 'http://appc.me/Content/kitten.jpg',
        width: 750, height: 426,
        hires: true
    }));
    canvas.add(scroll);
    // Add some text.
    canvas.add(Ti.UI.createLabel({
        text: 'Kittens are the best.', textAlign: 'center',
        font: { fontSize: 28 },
        color: '#000',
        bottom: 20
    }));
    // Add the canvas to the win.
    win.add(canvas);
    
    // Second, create the "save" button.
    var save = Ti.UI.createButton({
        title: 'Save to Gallery',
        height: 30, width: Ti.UI.SIZE,
        bottom: 10, right: 10
    });
    save.addEventListener('click', function (evt) {
        // Turn our "canvas" view (and its children) in to an image,
        // and save it to the gallery.
        Ti.Media.saveToPhotoGallery(canvas.toImage(), {
            success: function () {
                alert('Saved!');
            },
            error: function () {
                alert('Oh no...');
            }
        });
    });
    // Add it to the win.
    win.add(save);
    
    win.open();
    

提交回复
热议问题