我想要將自定義識別器的手勢移除到圖像視圖。這是來自kerby turner的一個手指輪換。有選擇地刪除自定義手勢識別器
-(void) enableRotation{
[[self mainImageView] setUserInteractionEnabled:YES];
[self addRotationGestureToView:[self mainImageView]];
//[self addTapGestureToView:[self mainImageView] numberOfTaps:1];
}
- (void)addTapGestureToView:(UIView *)view numberOfTaps:(NSInteger)numberOfTaps
{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[tap setNumberOfTapsRequired:numberOfTaps];
[view addGestureRecognizer:tap];
}
- (void)addRotationGestureToView:(UIView *)view
{
NSLog(@"'Adding KT Rotation recognizer to the rotation");
KTOneFingerRotationGestureRecognizer *rotation = [[KTOneFingerRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotating:)];
[view addGestureRecognizer:rotation];
}
- (void)rotating:(KTOneFingerRotationGestureRecognizer *)recognizer
{
UIView *view = [recognizer view];
[view setTransform:CGAffineTransformRotate([view transform], [recognizer rotation])];
}
- (void)removeRotationGestureFromView: (UIImageView *) imgView {
//UIRotationGestureRecognizer *rotate = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationRemoved:)];
//[imgView removeGestureRecognizer:rotate];
KTOneFingerRotationGestureRecognizer *rotation = [[KTOneFingerRotationGestureRecognizer alloc] init];
while(self.mainImageView.gestureRecognizers.count){
[self.mainImageView removeGestureRecognizer:[self.mainImageView.gestureRecognizers objectAtIndex:0]];
//[self.mainImageView removeGestureRecognizer:rotation];
}
NSLog(@"Trying to remove rotation on this gesture");
}
我定製tile標籤
if(rotationToggle%2==0){
[self enableRotation];
NSLog(@"%d", rotationToggle);
}
else{
[self removeRotationGestureFromView:self.mainImageView];
NSLog(@"%d", rotationToggle);
}
rotationToggle +=1;
其中rotationToggle是靜態INT調用它。
如何刪除只有一個手勢識別器。當前方法刪除圖像視圖中的所有識別器。如果我只是 [imgView removeGestureRecognizer:rotate]; 或 [self.mainImgView removeGestureRecognizer:rotate];
它不起作用。提前致謝。讓我知道,如果我忘記在這裏提到的東西。
PLZ忽略雙擊手勢操作 – CalZone 2013-03-06 23:06:01