[TIMOB-5224] Android: Expose "pinch" events in Ti.UI.View
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-04-30T08:32:53.000+0000 |
Affected Version/s | Release 1.8.0 |
Fix Version/s | Release 2.1.0 |
Components | Android |
Labels | core, qe-testadded |
Reporter | John V Pataki |
Assignee | Neeraj Gupta |
Created | 2011-09-06T16:14:36.000+0000 |
Updated | 2021-10-25T22:22:47.000+0000 |
Description
We need to have the event handler for pinch gestures available for TIUIView objects and their derivatives
This is needed for many projects we've been a apart of.
We recently implemented this in the soon to be available openGL module development project (ios only so far) and it seems to work for our needs there.
Having this available for all views and objects that are based on view objects would be very useful.
Here are the code snippets from the IOS side:
Added this to the view initialization:
UIPinchGestureRecognizer *pinchRecognizer;
pinchRecognizer=[[UIPinchGestureRecognizer alloc]
initWithTarget:self
action:@selector(foundPinch:)];
[controller.view addGestureRecognizer:pinchRecognizer];
[pinchRecognizer release];
here's the callback:
- (void)foundPinch:(UIPinchGestureRecognizer *)recognizer {
NSDictionary *event = [NSDictionary dictionaryWithObjectsAndKeys:NUMDOUBLE(recognizer.scale), @"scale", NUMDOUBLE(recognizer.velocity), @"velocity", nil];
[self.proxy fireEvent:@"pinch" withObject:event];
}
here's how we use it now on the opengl view
opengl.addEventListener('pinch', function {
scale = e.scale;
});
Test Case
var baseHeight = 200;
var baseWidth = 200;
var win = Ti.UI.createWindow({
backgroundColor: '#fff',
fullscreen: false,
exitOnClose: true
});
var view = Ti.UI.createView({
height: baseHeight,
width: baseWidth,
backgroundColor: '#a00'
});
var label = Ti.UI.createLabel({
text: baseWidth + ' x ' + baseHeight,
color: '#fff',
font: {
fontSize: 24,
fontWeight: 'bold'
}
});
view.add(label);
win.add(view);
view.addEventListener('pinch', function(e) {
view.height = baseHeight * e.scale;
view.width = baseWidth * e.scale;
label.text = Math.round(view.width) + ' x ' + Math.round(view.height);
});
view.addEventListener('touchstart', function(e) {
baseHeight = view.height;
baseWidth = view.width;
});
win.open();
Closing as Fixed. Verified via test case. SDK: 2.1.0.v20120606105255 Studio: 2.1.0.201206051612 Android: V8, Rhino Devices Tested: Nexus One 2.2.2, Xoom 4.0.3, Revolution 2.3.6
This works great for a single view in a window but I was unable to get imageviews to zoom in a scrollableview. Is this a bug or just a technical limitation of views inside scrollableviews? Is there possibly a hack to allow a imageview to zoom in a scollableview?