Comments (1)
Update this works on the simulator but not on the device have absolutely no idea why ;(
var container = Ti.UI.createView({
backgroundColor : 'blue',
borderRadius: 144,
width : 288,
height : 288
});
var free = Draggable.createView({
opacity : 0,
backgroundColor : 'transparent',
borderWidth : 4,
borderColor : '#101010',
borderRadius : 30,
width : 60,
height : 60,
zIndex : 2
});
free.addEventListener('move', function(e) {
var circle_cenx = container.width / 2;
var circle_cenx = container.width / 2;
var circle_ceny = container.width / 2;
var circle_radius = container.width / 2;
var result = limit(e.center.x, e.center.y, circle_cenx, circle_ceny, circle_radius);
Ti.API.info("X: " + result.x);
Ti.API.info("Y: " + result.y);
free.left = (result.x - (free.width / 2));
free.top = (result.y - (free.height / 2));
Ti.API.info("free.left: " + (result.x - 30));
Ti.API.info("free.top: " + (result.y - 30));
});
function limit(x, y, cenx, ceny, r) {
var dist = distance([x, y], [cenx, ceny]);
if (dist <= r) {
return {
x : x,
y : y
};
} else {
x = x - cenx;
y = y - ceny;
var radians = Math.atan2(y, x);
return {
x : Math.cos(radians) * r + cenx,
y : Math.sin(radians) * r + ceny
};
}
}
function distance(dot1, dot2) {
var x1 = dot1[0],
y1 = dot1[1],
x2 = dot2[0],
y2 = dot2[1];
return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
}
from tidraggable.
Related Issues (20)
- Need minBottom and maxBottom property
- Ti.Draggable Not Supported by TitaniumSDK 5.0.0.GA HOT 6
- Draggable Views inside a ScrollView disable scrolling when enabled set to false HOT 1
- Android build
- Draggable in Scrollableview
- Draggable in Scrollableview
- Module crashes app on Android 6 device with "text relocations" error
- How to create a snap effect? HOT 1
- how to add the view to a listview item?
- Version 2.0.4 buid link ? HOT 1
- Crash on Xperia3+ with Android 6.0.1, SDK 5.5.1.GA HOT 1
- Is it possible to allow clicks to a Draggable view to pass to views underneath?
- Seems like it needs to be recompiled for SDK 6.0.0 HOT 1
- Android zip module HOT 2
- ti.draggable-android-2.1.4 HOT 7
- Not compatiable for ti sdk 7.5.0.GA HOT 1
- Ti.Draggable (Android module) for Ti SDK 9.0 - found!
- Installation Instructions or Zip File HOT 1
- New version for iOS
- End event's e.top property on android
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tidraggable.