Permalink
Browse files

added Pan gesture.

  • Loading branch information...
atsusy committed Oct 22, 2011
1 parent 0bf37a8 commit be8e48ab8785b59470b710fda52507734ba471ec
View
@@ -2,9 +2,11 @@
*.perspective
*.perspectivev3
*.mode1v3
+*.xcuserstate
project.xcworkspace
xcuserdata
tmp
bin
build
*.zip
+*~
@@ -10,4 +10,5 @@
@interface TiUIView (TiUIView_GestureRecognizer)
- (void)setRotateGesture_:(id)value;
- (void)setPinchGesture_:(id)value;
+- (void)setPanGesture_:(id)value;
@end
@@ -101,4 +101,53 @@ - (void)setPinchGesture_:(id)value
}
}
}
+
+- (void)handlePanGesture:(UIPanGestureRecognizer *)sender
+{
+ CGPoint translation = [sender translationInView:self.window];
+ CGPoint velocity = [sender velocityInView:self.window];
+
+ NSDictionary *args = [NSDictionary dictionaryWithObjectsAndKeys:
+ [[[TiPoint alloc] initWithPoint:translation] autorelease], @"translation",
+ [[[TiPoint alloc] initWithPoint:velocity] autorelease], @"velocity", nil];
+ if([self.proxy _hasListeners:@"pan"]){
+ [self.proxy fireEvent:@"pan" withObject:args];
+ }
+
+ if(sender.state == UIGestureRecognizerStateEnded &&
+ [self.proxy _hasListeners:@"panend"]){
+ [self.proxy fireEvent:@"panend"];
+ }
+}
+
+- (void)setPanGesture_:(id)value
+{
+ ENSURE_SINGLE_ARG(value, NSNumber);
+ BOOL value_ = [value boolValue];
+
+ if(value_){
+ for(UIGestureRecognizer *gesure in self.gestureRecognizers){
+ if([gesure isKindOfClass:[UIPanGestureRecognizer class]]){
+ return;
+ }
+ }
+
+ UIPanGestureRecognizer *panGesture =[[UIPanGestureRecognizer alloc] initWithTarget:self
+ action:@selector(handlePanGesture:)];
+ [self addGestureRecognizer:panGesture];
+
+ [panGesture release];
+ } else{
+ UIGestureRecognizer *panGesture = nil;
+ for(UIGestureRecognizer *gesure in self.gestureRecognizers){
+ if([gesure isKindOfClass:[UIPanGestureRecognizer class]]){
+ panGesture = gesure;
+ break;
+ }
+ }
+ if(panGesture){
+ [self removeGestureRecognizer:panGesture];
+ }
+ }
+}
@end
View
BIN Icon.xcf
Binary file not shown.
View
@@ -1,47 +1,50 @@
-# GestureReognizer Module
+# Gesture Recognizer Module
## Description
This module extends rotateGesture and pinchGesture property to your view.
## Accessing the repeatedbackgroundimage Module
-Append inside <modules> tag <module version="1.0">jp.msmc.gesturerecognizer</module>.
+Declare to tiapp.xml like below.
+
+ <modules>
+ <module version="1.0">jp.msmc.gesturerecognizer</module>
+ </modules>
## Reference
This module has no property and function.
## Usage
-
-var image = Ti.UI.createImageView({
- rotateGesture:true,
- pinchGesture:true
-});
-
-// callback on rotation gesture.
-image.addEventListener('rotate', function(e){
- e.rotation; // this is rotation angle(radian)
- e.velocity; // this is gesture speed
-});
-
-// callback on rotation gesture finished.
-image.addEventListner('rotateend', function(e){
-});
-
-// callback on pinch gesture.
-image.addEventListener('pinch', function(e){
- e.scale; // this is scale
- e.velocity; // this is gesture speed
-});
-
-// callback on pinch gesture finished.
-image.addEventListener('pinchend', function(e){
-});
+ var image = Ti.UI.createImageView({
+ rotateGesture:true,
+ pinchGesture:true
+ });
+
+ // callback on rotation gesture.
+ image.addEventListener('rotate', function(e){
+ e.rotation; // this is rotation angle(radian)
+ e.velocity; // this is gesture speed
+ });
+
+ // callback on rotation gesture finished.
+ image.addEventListner('rotateend', function(e){
+ });
+
+ // callback on pinch gesture.
+ image.addEventListener('pinch', function(e){
+ e.scale; // this is scale
+ e.velocity; // this is gesture speed
+ });
+
+ // callback on pinch gesture finished.
+ image.addEventListener('pinchend', function(e){
+ });
## Author
-KATAOKA,Atsushi <atsushi.kataoka@msmc.jp>
+KATAOKA,Atsushi `<atsushi.kataoka@msmc.jp>`
## License
View
@@ -6,24 +6,44 @@
// open a single window
var window = Ti.UI.createWindow({
+ orientationModes:[
+ Ti.UI.LANDSCAPE_LEFT,
+ Ti.UI.LANDSCAPE_RIGHT,
+ Ti.UI.PORTRAIT,
+ Ti.UI.UPSIDE_PORTRAIT
+ ]
});
var image = Ti.UI.createImageView({
- image:"lena_std.jpg",
+ image:"toby.jpg",
rotateGesture:true,
- pinchGesture:true
+ pinchGesture:true,
+ panGesture:true
});
var lastAngle = 0.0;
var currentAngle = 0.0;
var lastScale = 1.0;
var currentScale = 1.0;
+var currentTranslation = {x:0.0, y:0.0};
+var lastTranslation = {x:0.0, y:0.0};
+
+function updateTransform(image)
+{
+ var transform = Ti.UI.create2DMatrix()
+ .scale(lastScale*currentScale)
+ .rotate(lastAngle+currentAngle);
+
+ transform.tx = lastTranslation.x+currentTranslation.x;
+ transform.ty = lastTranslation.y+currentTranslation.y;
+
+ image.transform = transform;
+};
+
image.addEventListener('rotate', function(e){
currentAngle = e.rotation / Math.PI * 180.0;
- image.transform = Ti.UI.create2DMatrix()
- .scale(lastScale*currentScale)
- .rotate(lastAngle+currentAngle);
+ updateTransform(image);
});
image.addEventListener('rotateend', function(e){
@@ -33,16 +53,27 @@ image.addEventListener('rotateend', function(e){
image.addEventListener('pinch', function(e){
currentScale = e.scale;
- image.transform = Ti.UI.create2DMatrix()
- .scale(lastScale*currentScale)
- .rotate(lastAngle+currentAngle);
+ updateTransform(image);
});
image.addEventListener('pinchend', function(e){
lastScale = (lastScale * currentScale);
currentScale = 1.0;
});
+image.addEventListener('pan', function(e){
+ currentTranslation.x = e.translation.x;
+ currentTranslation.y = e.translation.y;
+ updateTransform(image);
+});
+
+image.addEventListener('panend', function(e){
+ lastTranslation.x = lastTranslation.x + currentTranslation.x;
+ lastTranslation.y = lastTranslation.y + currentTranslation.y;
+ currentTranslation.x = 0.0;
+ currentTranslation.y = 0.0;
+});
+
window.add(image);
window.open();
View
Binary file not shown.
@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 45;
+ objectVersion = 46;
objects = {
/* Begin PBXAggregateTarget section */
@@ -155,8 +155,11 @@
/* Begin PBXProject section */
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0420;
+ };
buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "gesturerecognizer" */;
- compatibilityVersion = "Xcode 3.1";
+ compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
@@ -223,7 +226,6 @@
COPY_PHASE_STRIP = NO;
DSTROOT = /tmp/JpMsmcGesturerecognizer.dst;
GCC_DYNAMIC_NO_PIC = NO;
- GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
@@ -252,28 +254,34 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 24DD6D1B1134B66800162E58 /* titanium.xcconfig */;
buildSettings = {
- ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ ARCHS = (
+ armv6,
+ "$(ARCHS_STANDARD_32_BIT)",
+ );
GCC_C_LANGUAGE_STANDARD = c99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
OTHER_LDFLAGS = "";
- PREBINDING = NO;
- SDKROOT = iphoneos4.0;
+ SDKROOT = iphoneos;
+ TITANIUM_SDK_VERSION = 1.7.2;
};
name = Debug;
};
1DEB922408733DC00010E9CD /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 24DD6D1B1134B66800162E58 /* titanium.xcconfig */;
buildSettings = {
- ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ ARCHS = (
+ armv6,
+ "$(ARCHS_STANDARD_32_BIT)",
+ );
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
OTHER_LDFLAGS = "";
- PREBINDING = NO;
- SDKROOT = iphoneos4.0;
+ SDKROOT = iphoneos;
+ TITANIUM_SDK_VERSION = 1.7.2;
};
name = Release;
};
@@ -294,7 +302,6 @@
buildSettings = {
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
- GCC_ENABLE_FIX_AND_CONTINUE = NO;
PRODUCT_NAME = "Build & test";
ZERO_LINK = NO;
};
View
@@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
-version: 1.0
+version: 1.1
description: Support Rotate and Pinch-in/out gesture to View.
author: KATAOKA,Atsushi
license: MIT License
View
Binary file not shown.

0 comments on commit be8e48a

Please sign in to comment.