在scrollView上检测PinchGesture END

时间:2011-01-23 12:19:21

标签: uiscrollview uigesturerecognizer gesture zooming

我有一个scrollView,我想在捏合手势结束时做一个动作。

SampleController.h

@interface SampleController : UIViewController <UIPopoverControllerDelegate,UITableViewDelegate>{
    IBOutlet UIScrollView *mapScrollView;
}
@property (nonatomic, retain) IBOutlet UIScrollView *mapScrollView;
@end

SampleController.m

@implementation SampleController

@synthesize mapScrollView;

- (void)viewDidLoad {
    [super viewDidLoad];

UIPinchGestureRecognizer *pinchRecognizer = 
    [[UIPinchGestureRecognizer alloc] 
     initWithTarget:self 
     action:@selector(handlePinchFrom:)];
    [mapScrollView addGestureRecognizer:pinchRecognizer];
    [pinchRecognizer release];
}

- (void)handlePinchFrom:(UIPinchGestureRecognizer *)recognizer {
    if(recognizer.state == UIGestureRecognizerStateEnded)
       {
           NSLog(@"handleTapEND");
       }
    else
    {
        NSLog(@"zooming ...");
    }
}

- (void)dealloc {
    [mapScrollView release];
    [super dealloc];
}

@end

我的问题是:

当我使用pinchRecognizer 时会阻止mapScrollView的滚动

还有其他方法可以检测滚动结束或ScrollView上的缩放吗?

谢谢,

布鲁诺

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

我的控制器上有一个计时器,如果发生滚动或拖动,它会继续执行操作:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.mapTimer = [[NSTimer 
                            scheduledTimerWithTimeInterval:1.0f 
                            target:self 
                            selector:@selector(updateDisplay:) 
                            userInfo:nil 
                            repeats:YES] retain];
}

- (void)updateDisplay:(NSTimer*)theTimer {

    if(mapHasMoved)
    {
        NSLog(@"updateDisplay");
        [self updateProducts];
        mapHasMoved = FALSE;
    }
}

- (void)endZoomingOrScrollingHandler{

    mapHasMoved = TRUE;
}