iOS UIScrollView上加子視圖touchMove手勢(shì)沖突

項(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;

?? ? }

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容