Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(all): Add rotate event #13882

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

feat(all): Add rotate event #13882

wants to merge 5 commits into from

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Jul 18, 2023

old 2019 PR #11411 but with iOS event too!

// if true it will rotate/scale the view - listener is on the window
// if false it will only show the scale/rotation value in the labels - listener is added to the view
//
var applyValues = true;

const win = Ti.UI.createWindow();
const v = Ti.UI.createView({width: 100,height: 100,backgroundColor: "#f00", touchEnabled: !applyValues});
const lbl1 = Ti.UI.createLabel({top: 10, text:"Scale: -"});
const lbl2 = Ti.UI.createLabel({top: 40, text:"Rotation: -"});

if (!applyValues) {
        v.addEventListener("rotate", onRotate);
        v.addEventListener("pinch", onScale);
} else {
        win.addEventListener("rotate", onRotate);
        win.addEventListener("pinch", onScale);
}

win.add([v, lbl1, lbl2]);
win.open();

function onScale(e) {
        lbl1.text = e.scale.toPrecision(2);

        if (applyValues) {
                v.scaleX = e.scale;
                v.scaleY = e.scale;
        }
}

function onRotate(e) {
        lbl2.text = e.rotate.toPrecision(2);
        if (applyValues) {
                if (Ti.Platform.osname === 'android') {
                        v.rotation = e.rotate; // android
                } else {
                        var matrix2d = Ti.UI.createMatrix2D();
                        matrix2d = matrix2d.rotate(e.rotate); // in degrees
                        var a = Ti.UI.createAnimation({
                                transform: matrix2d,
                                duration: 1,
                        });
                        v.animate(a); // ios
                }
        }
}
screencapture-2022-03-27_17.02.17.mp4

@m1ga m1ga changed the title 230718 rotate event feat(all): Add rotate event Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant