iOS 제스처 및 터치
터치 #
터치에 포함된 정보는 다음과 같습니다.
제스처 인식기 #
이것은 애플이 제공한 강력한 식별 방식이다.알잖아!iOS SDK 내장형 제스처
@implementation DragView
{
CGPoint startLocation;
}
-(instancetype)initWithImage:(UIImage *)anImage
{
self=[super initWithImage:anImage];
if(self)
{
self.userInteractionEnabled=YES;
}
return self;
}
-(void)touchBegan:(NSSet *)touches withEvent:(UIEvent *)event{
startLocation =[[touches anyObject] locationInView:self];
[self.superview bringSubviewToFront:self];//
}
-(void)touchMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CGPiont pt=[[touches anyObject] locationInView:self];
float dx=pt.x-startLocation.x;
float dy=pt.y-startLocation.y;
CGPiont newcenter=CGPonitMake(
self.center.x+dx,self.center.y+dy);
self.center=newcenter;
}
제스처 식별기로 실현
@implementation DragView
{
CGPoint spreviousLocation;
}
-(instancetype)initWithImage:(UIImage *)anImage
{
self=[super initWithImage:anImage];
if(self)
{
self.userInteractionEnabled=YES;
UIPanGestureRecongnizer *panGesture=[[UIPanGestureRecongnizer alloc]initWithTarget:self action: @selector(handlePan:)];
self.gestureRecognizers=@[panGesture];
}
return self;
}
-(void)touchBegan:(NSSet *)touches withEvent:(UIEvent *)event{
spreviousLocation =self.center;
[self.superview bringSubviewToFront:self];//
}
-(void)hanlePan:(UIPanGestureRecongnizer *)sender{
CGPoint tanslation=[sender translationInView:self,superview];
self.center=CGPonitMake(spreviousLocation.x+tanslation.x,spreviousLocation.y+tanslation.y);
}