using gesture to drag

This commit is contained in:
Feather
2013-04-18 13:49:15 +08:00
parent cc5314f2ba
commit b1ae5e6043
6 changed files with 89 additions and 127 deletions

View File

@@ -17,11 +17,8 @@
67C603131717C6A500629C0E /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 67C603121717C6A500629C0E /* Default@2x.png */; };
67C603151717C6A500629C0E /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 67C603141717C6A500629C0E /* Default-568h@2x.png */; };
67C603181717C6A500629C0E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 67C603171717C6A500629C0E /* ViewController.m */; };
67C6031B1717C6A500629C0E /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 67C603191717C6A500629C0E /* ViewController.xib */; };
67C603251717DE5A00629C0E /* leftside_shadow_bg@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 67C603241717DE5A00629C0E /* leftside_shadow_bg@2x.png */; };
67D2EA04171E415800071E64 /* MLTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 67D2EA03171E415800071E64 /* MLTableView.m */; };
67F1E622171D11C800A8CE9F /* MLNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 67F1E61F171D11C800A8CE9F /* MLNavigationController.m */; };
67F1E623171D11C800A8CE9F /* MLScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 67F1E621171D11C800A8CE9F /* MLScrollView.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -40,14 +37,9 @@
67C603141717C6A500629C0E /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
67C603161717C6A500629C0E /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
67C603171717C6A500629C0E /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
67C6031A1717C6A500629C0E /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = "<group>"; };
67C603241717DE5A00629C0E /* leftside_shadow_bg@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "leftside_shadow_bg@2x.png"; sourceTree = "<group>"; };
67D2EA02171E415800071E64 /* MLTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MLTableView.h; sourceTree = "<group>"; };
67D2EA03171E415800071E64 /* MLTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MLTableView.m; sourceTree = "<group>"; };
67F1E61E171D11C800A8CE9F /* MLNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MLNavigationController.h; sourceTree = "<group>"; };
67F1E61F171D11C800A8CE9F /* MLNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MLNavigationController.m; sourceTree = "<group>"; };
67F1E620171D11C800A8CE9F /* MLScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MLScrollView.h; sourceTree = "<group>"; };
67F1E621171D11C800A8CE9F /* MLScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MLScrollView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -99,7 +91,6 @@
67C6030E1717C6A500629C0E /* AppDelegate.m */,
67C603161717C6A500629C0E /* ViewController.h */,
67C603171717C6A500629C0E /* ViewController.m */,
67C603191717C6A500629C0E /* ViewController.xib */,
67C603051717C6A500629C0E /* Supporting Files */,
);
path = MultiLayerNavigation;
@@ -125,10 +116,6 @@
children = (
67F1E61E171D11C800A8CE9F /* MLNavigationController.h */,
67F1E61F171D11C800A8CE9F /* MLNavigationController.m */,
67F1E620171D11C800A8CE9F /* MLScrollView.h */,
67F1E621171D11C800A8CE9F /* MLScrollView.m */,
67D2EA02171E415800071E64 /* MLTableView.h */,
67D2EA03171E415800071E64 /* MLTableView.m */,
);
path = Src;
sourceTree = SOURCE_ROOT;
@@ -188,7 +175,6 @@
67C603111717C6A500629C0E /* Default.png in Resources */,
67C603131717C6A500629C0E /* Default@2x.png in Resources */,
67C603151717C6A500629C0E /* Default-568h@2x.png in Resources */,
67C6031B1717C6A500629C0E /* ViewController.xib in Resources */,
67C603251717DE5A00629C0E /* leftside_shadow_bg@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -204,8 +190,6 @@
67C6030F1717C6A500629C0E /* AppDelegate.m in Sources */,
67C603181717C6A500629C0E /* ViewController.m in Sources */,
67F1E622171D11C800A8CE9F /* MLNavigationController.m in Sources */,
67F1E623171D11C800A8CE9F /* MLScrollView.m in Sources */,
67D2EA04171E415800071E64 /* MLTableView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -220,14 +204,6 @@
name = InfoPlist.strings;
sourceTree = "<group>";
};
67C603191717C6A500629C0E /* ViewController.xib */ = {
isa = PBXVariantGroup;
children = (
67C6031A1717C6A500629C0E /* en */,
);
name = ViewController.xib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */

View File

@@ -2,6 +2,21 @@
<Bucket
type = "1"
version = "1.0">
<FileBreakpoints>
<FileBreakpoint
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Src/MLNavigationController.m"
timestampString = "387956716.744312"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "115"
endingLineNumber = "115"
landmarkName = "-moveViewWithX:"
landmarkType = "5">
</FileBreakpoint>
</FileBreakpoints>
<ExceptionBreakpoints>
<ExceptionBreakpoint
shouldBeEnabled = "Yes"

View File

@@ -7,7 +7,6 @@
//
#import <UIKit/UIKit.h>
#import "MLTableView.h"
@interface ViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>

View File

@@ -8,7 +8,6 @@
#import "ViewController.h"
#import "MLNavigationController.h"
#import "MLScrollView.h"
@interface ViewController ()
@@ -39,20 +38,20 @@
UILabel *textView = [[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 180)]autorelease];
textView.font = [UIFont systemFontOfSize:12];
textView.text = @"MultiLayerNavigation helps you implemntation the interaction -- 'drag to back' in a easy way.\n The only one thing you need to do is replacing your UINavigationController with the MLNavigation Controller or inherit it. \n In addtion, if there are a scroll view in your ViewController, you need to do one more thing -- replace the UIScrollView with MLScrollView or inherit it, that's all.";
textView.text = @"MultiLayerNavigation helps you implemntation the interaction -- 'drag to back' in a easy way.\n The only one thing you need to do is replacing your UINavigationController with the MLNavigation Controller or inherit it.";
textView.numberOfLines = 0;
// MLScrollView *scrollView = [[[MLScrollView alloc]initWithFrame:CGRectMake(0,300,320,140)]autorelease];
// scrollView.contentSize = CGSizeMake(320, 200);
// scrollView.userInteractionEnabled = YES;
// [scrollView addSubview:textView];
// [self.view addSubview:scrollView];
UIScrollView *scrollView = [[[UIScrollView alloc]initWithFrame:CGRectMake(0,300,320,140)]autorelease];
scrollView.contentSize = CGSizeMake(320, 200);
scrollView.userInteractionEnabled = YES;
[scrollView addSubview:textView];
[self.view addSubview:scrollView];
MLTableView *tableView = [[[MLTableView alloc]initWithFrame:CGRectMake(0, 300, 320, 140)]autorelease];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
// UITableView *tableView = [[[UITableView alloc]initWithFrame:CGRectMake(0, 300, 320, 140)]autorelease];
// tableView.delegate = self;
// tableView.dataSource = self;
// [self.view addSubview:tableView];
}

View File

@@ -68,7 +68,10 @@
shadowImageView.frame = CGRectMake(-10, 0, 10, self.view.frame.size.height);
[self.view addSubview:shadowImageView];
UIPanGestureRecognizer *recognizer = [[[UIPanGestureRecognizer alloc]initWithTarget:self
action:@selector(paningGestureReceive:)]autorelease];
[recognizer delaysTouchesBegan];
[self.view addGestureRecognizer:recognizer];
}
- (void)didReceiveMemoryWarning
@@ -108,7 +111,7 @@
- (void)moveViewWithX:(float)x
{
NSLog(@"Move to:%f",x);
x = x>320?320:x;
x = x<0?0:x;
@@ -124,108 +127,78 @@
}
#pragma mark - UIResponse Subclassing Methods -
#pragma mark - Gesture Recognizer -
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- (void)paningGestureReceive:(UIPanGestureRecognizer *)recoginzer
{
// NSLog(@"navi touch begin");
[super touchesBegan:touches withEvent:event];
if (self.viewControllers.count <= 1 || !self.canDragBack) return;
_isMoving = NO;
startTouch = [((UITouch *)[touches anyObject])locationInView:KEY_WINDOW];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
CGPoint touchPoint = [recoginzer locationInView:KEY_WINDOW];
// NSLog(@"navi touch move:%f",[((UITouch *)[touches anyObject])locationInView:KEY_WINDOW].x);
if (self.viewControllers.count <= 1 || !self.canDragBack) return;
CGPoint moveTouch = [((UITouch *)[touches anyObject])locationInView:KEY_WINDOW];
if (!_isMoving) {
if(moveTouch.x - startTouch.x > 10)
if (recoginzer.state == UIGestureRecognizerStateBegan) {
_isMoving = YES;
startTouch = touchPoint;
if (!self.backgroundView)
{
_isMoving = YES;
if (!self.backgroundView)
{
CGRect frame = self.view.frame;
self.backgroundView = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width , frame.size.height)]autorelease];
[self.view.superview insertSubview:self.backgroundView belowSubview:self.view];
blackMask = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width , frame.size.height)]autorelease];
blackMask.backgroundColor = [UIColor blackColor];
[self.backgroundView addSubview:blackMask];
}
if (lastScreenShotView) [lastScreenShotView removeFromSuperview];
UIImage *lastScreenShot = [self.screenShotsList lastObject];
lastScreenShotView = [[[UIImageView alloc]initWithImage:lastScreenShot]autorelease];
[self.backgroundView insertSubview:lastScreenShotView belowSubview:blackMask];
}
}
if (_isMoving) {
[self moveViewWithX:moveTouch.x - startTouch.x];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// NSLog(@"navi touch end");
[super touchesEnded:touches withEvent:event];
if (self.viewControllers.count <= 1 || !self.canDragBack) return;
CGPoint endTouch = [((UITouch *)[touches anyObject])locationInView:KEY_WINDOW];
if (endTouch.x - startTouch.x > 50)
{
[UIView animateWithDuration:0.3 animations:^{
[self moveViewWithX:320];
} completion:^(BOOL finished) {
[self popViewControllerAnimated:NO];
CGRect frame = self.view.frame;
frame.origin.x = 0;
self.view.frame = frame;
_isMoving = NO;
}];
}
else
{
self.backgroundView = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width , frame.size.height)]autorelease];
[self.view.superview insertSubview:self.backgroundView belowSubview:self.view];
blackMask = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width , frame.size.height)]autorelease];
blackMask.backgroundColor = [UIColor blackColor];
[self.backgroundView addSubview:blackMask];
}
if (lastScreenShotView) [lastScreenShotView removeFromSuperview];
UIImage *lastScreenShot = [self.screenShotsList lastObject];
lastScreenShotView = [[[UIImageView alloc]initWithImage:lastScreenShot]autorelease];
[self.backgroundView insertSubview:lastScreenShotView belowSubview:blackMask];
}else if (recoginzer.state == UIGestureRecognizerStateEnded){
if (touchPoint.x - startTouch.x > 50)
{
[UIView animateWithDuration:0.3 animations:^{
[self moveViewWithX:320];
} completion:^(BOOL finished) {
[self popViewControllerAnimated:NO];
CGRect frame = self.view.frame;
frame.origin.x = 0;
self.view.frame = frame;
_isMoving = NO;
}];
}
else
{
[UIView animateWithDuration:0.3 animations:^{
[self moveViewWithX:0];
} completion:^(BOOL finished) {
_isMoving = NO;
}];
}
return;
}else if (recoginzer.state == UIGestureRecognizerStateCancelled){
[UIView animateWithDuration:0.3 animations:^{
[self moveViewWithX:0];
} completion:^(BOOL finished) {
_isMoving = NO;
}];
return;
}
if (_isMoving) {
[self moveViewWithX:touchPoint.x - startTouch.x];
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
// NSLog(@"navi touch cancel");
[super touchesCancelled:touches withEvent:event];
if (self.viewControllers.count <= 1 || !self.canDragBack) return;
[UIView animateWithDuration:0.3 animations:^{
[self moveViewWithX:0];
} completion:^(BOOL finished) {
_isMoving = NO;
}];
}
@end