iOS - 제스처 세부 매개 변수 설명
// UILabel ( )
UILabel *demoLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
//
// 1.
// 2.
UITapGestureRecognizer *tapFs = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapFs:)];
//
[demoLabel addGestureRecognizer:tapFs];
//
tapFs.numberOfTapsRequired = 1; //
//
tapFs.numberOfTouchesRequired = 1;
//
UITapGestureRecognizer *tapSe = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapSe:)];
//
[demoLabel addGestureRecognizer:tapSe];
//
tapSe.numberOfTapsRequired = 2;
//
[tapFs requireGestureRecognizerToFail:tapSe];
-(void)tapGesture:(UITapGestureRecognizer *)tap{
NSLog(@" demoLabel");
}
-(void)twoTapGesture:(UITapGestureRecognizer *)tap{
NSLog(@" demoLabel");
}
손짓
//
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
//
[demoLabel addGestureRecognizer:longPress];
//
longPress.minimumPressDuration = 3;// 0.5s
// , ,
longPress.allowableMovement = 50;
-(void)longPress:(UILongPressGestureRecognizer *)longPress{
//【 】 , ,
// : ,
if (longPress.state == UIGestureRecognizerStateEnded) {
NSLog(@" demoLabel");
}
}
슬라이딩 제스처
//
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
[demoLabel addGestureRecognizer:swipe];
/**
UISwipeGestureRecognizerDirectionRight
UISwipeGestureRecognizerDirectionLeft
UISwipeGestureRecognizerDirectionUp
UISwipeGestureRecognizerDirectionDown
*/
// :
swipe.direction = UISwipeGestureRecognizerDirectionRight;
-(void)swipe:(UISwipeGestureRecognizer *)sw{
switch (sw.direction) {
case UISwipeGestureRecognizerDirectionRight:
NSLog(@" ");
break;
case UISwipeGestureRecognizerDirectionLeft:
NSLog(@" ");
break;
case UISwipeGestureRecognizerDirectionUp:
NSLog(@" ");
break;
case UISwipeGestureRecognizerDirectionDown:
NSLog(@" ");
break;
default:
NSLog(@" ");
break;
}
}
드래그 제스처
//
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)];
[demoLabel addGestureRecognizer:pan];
// (max ,min )
pan.maximumNumberOfTouches = 3;
pan.minimumNumberOfTouches = 1;
// ,
-(void)panGesture:(UIPanGestureRecognizer *)pan{
//
CGPoint point = [pan translationInView:self.view];
//
demoLabel.center = CGPointMake(demoLabel.center.x + point.x, demoLabel.center.y + point.y);
//
[pan setTranslation:CGPointZero inView:self.view];
}
회전 제스처
//
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture:)];
[demoLabel addGestureRecognizer:rotation];
//
-(void)rotationGesture:(UIRotationGestureRecognizer *)rotation{
demoLabel.transform = CGAffineTransformRotate(demoLabel.transform, rotation.rotation);
//
rotation.rotation = 0;
}
손짓
//
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGesture:)];
//
[demoLabel addGestureRecognizer:pinch];
//
-(void)pinchGesture:(UIPinchGestureRecognizer *)pinch{
demoLabel.transform = CGAffineTransformScale(_label.transform, pinch.scale, pinch.scale);
//
pinch.scale = 1;
}
두 가지 제스처가 같은 보기에 작용한다
//
//
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture:)];
rotation.delegate = self;
[demoLabel addGestureRecognizer:rotation];
//
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGesture:)];
pinch.delegate = self;
//
[demoLabel addGestureRecognizer:pinch];
//
-(void)rotationGesture:(UIRotationGestureRecognizer *)rotation{
demoLabel.transform = CGAffineTransformRotate(demoLabel.transform, rotation.rotation);
//
rotation.rotation = 0;
}
//
-(void)pinchGesture:(UIPinchGestureRecognizer *)pinch{
demoLabel.transform = CGAffineTransformScale(demoLabel.transform, pinch.scale, pinch.scale);
//
pinch.scale = 1;
}
// , , ,
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
// , , YES
return YES;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.