項(xiàng)目中有一個(gè)需求,在UIScrollView上加一個(gè)簽名區(qū)域,因?yàn)楹灻麉^(qū)域是用uiview的touchMove做的,會(huì)存在手勢(shì)沖突的問題,現(xiàn)在記錄一下解決辦法
1.給scrowView加一個(gè)類目重寫四個(gè)觸碰時(shí)間以便于控制器能夠重新接收到觸碰信息
#import "UIScrollView+touch.h"
- (void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event {
? ? NSLog(@"scrowView點(diǎn)擊");
? ? [supertouchesBegan:toucheswithEvent:event];
}
-(void)touchesMoved:(NSSet*)toucheswithEvent:(UIEvent*)event {
? ? ? NSLog(@"scrowViewh滑動(dòng)");
? ? [supertouchesMoved:toucheswithEvent:event];
}
- (void)touchesEnded:(NSSet*)toucheswithEvent:(UIEvent*)event {
? ? ? NSLog(@"scrowView結(jié)束點(diǎn)擊");
? ? [supertouchesEnded:toucheswithEvent:event];
}
- (void)touchesCancelled:(NSSet*)toucheswithEvent:(UIEvent*)event {
? ? [super touchesCancelled:touches withEvent:event];
}
2.給簽名的siginView也要寫上super touches方法
#import "HJSignatureView.h"
- (void)touchesBegan:(NSSet *)toucheswithEvent:(UIEvent*)event {
? ? NSLog(@"點(diǎn)擊");
? ? [supertouchesBegan:toucheswithEvent:event];
? ? UITouch*touch = [touchesanyObject];
? ? CGPointcurrentPoint = [touchlocationInView:self];
? ? [self.signaturePathmoveToPoint:currentPoint];
? ? self.oldPoint= currentPoint;
}
- (void)touchesMoved:(NSSet *)toucheswithEvent:(UIEvent*)event {
? ? [supertouchesMoved:toucheswithEvent:event];
? ? NSLog(@"書寫");
? ? UITouch*touch = [touchesanyObject];
? ? CGPointcurrentPoint = [touchlocationInView:self];
? ? [self.signaturePath addQuadCurveToPoint:currentPoint controlPoint:self.oldPoint];
? ? self.oldPoint= currentPoint;
? ? //設(shè)置剪切圖片的區(qū)域
? ? [selfgetImageRect:currentPoint];
? ? //設(shè)置簽名存在
? ? if (!self.isHaveSignature) {
? ? ? ? self.isHaveSignature = YES;
? ? }
? ? [self setNeedsDisplay];
}
-(void)touchesEnded:(NSSet *)toucheswithEvent:(UIEvent*)event
{
? ? [supertouchesEnded:toucheswithEvent:event];
}
3.在viewController里接受觸碰消息再判斷是從哪個(gè)view里傳來的,從而確定scrowview要不要滾動(dòng)
-(void)touchesMoved:(NSSet *)toucheswithEvent:(UIEvent*)event
{
?? ? UITouch* touch = [touchesanyObject];
?? ? UIView* view = [touchview];
?? ? if([viewisKindOfClass:[HJSignatureViewclass]]) {
? ? ? ? ? _mainScrowView.scrollEnabled=NO;
?? ? }else
?? ? {
?? ? ? ? _mainScrowView.scrollEnabled=YES;
}
}
- (void)touchesBegan:(NSSet *)toucheswithEvent:(UIEvent*)event
{
? ? UITouch* touch = [touchesanyObject];
? ? UIView* view = [touchview];
? ? if([viewisKindOfClass:[HJSignatureViewclass]]) {
?? ? ? ? _mainScrowView.scrollEnabled=NO;
? ? }else
? ? {
? ? ? ? _mainScrowView.scrollEnabled = YES;
? ? }
}
-(void)touchesEnded:(NSSet *)toucheswithEvent:(UIEvent*)event
{
?? ? UITouch* touch = [touchesanyObject];
?? ? UIView* view = [touchview];
?? ? if([viewisKindOfClass:[HJSignatureViewclass]]) {
? ? ? ? ? _mainScrowView.scrollEnabled=NO;
?? ? }else
?? ? {
?? ? ? ? _mainScrowView.scrollEnabled=YES;
?? ? }
}