UITapGestureRecognized
을 UIView
에 추가 한 경우, 즉 뷰를 어떻게 해석해야합니까? 탭 동안 배경색을 변경 하시겠습니까? 이것의 목적은 버튼 클릭을 모방하는 것입니다.모방 버튼을 클릭하여 UIGestureRecognized를 클릭하십시오.
UIView *locationView = [[UIView alloc] init];
locationView.tag = 11;
locationView.backgroundColor = [UIColor clearColor];
locationView.userInteractionEnabled = YES;
[locationView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(promptForLocation)]];
탭 제스처 직후 locationView.backgroundColor = [UIColor blueColor]
을 원한다고 가정 해 봅시다. 목표 액션에 구현할 것인가 아니면 특정 구현이 있습니까?
업데이트 : 이 나의 마지막 코드는
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// ...
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressDetectedLocation:)];
longPress.allowableMovement = 50.0f;
longPress.minimumPressDuration = 0.05;
UILongPressGestureRecognizer *longPress2 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressDetectedPhoto:)];
longPress2.allowableMovement = 50.0f;
longPress2.minimumPressDuration = 0.05;
[leftView addGestureRecognizer:longPress];
[rightView addGestureRecognizer:longPress2];
// ...
}
- (BOOL)longPressDetected:(UILongPressGestureRecognizer *)sender {
if ([self.view hasFirstResponder]) {
return NO;
}
if (sender.state == UIGestureRecognizerStateBegan) {
[sender.view setBackgroundColor:[UIColor colorWithRed:(4/255.0) green:(129/255.0) blue:(241/255.0) alpha:1]];
} else if (sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateFailed) {
[sender.view setBackgroundColor:[UIColor clearColor]];
}
CGPoint location = [sender locationInView:sender.view];
return sender.state == UIGestureRecognizerStateEnded && location.x > 0 && location.x < sender.view.frame.size.width && location.y > 0 && location.y < sender.view.frame.size.height;
}
- (void)longPressDetectedLocation:(UILongPressGestureRecognizer *)sender {
if ([self longPressDetected:sender]) {
[self promptForLocation];
}
}
- (void)longPressDetectedPhoto:(UILongPressGestureRecognizer *)sender {
if ([self longPressDetected:sender]) {
[self promptForPhoto];
}
}
이 꽤 좋은 해결 방법이다 :
다음은 예입니다. 좋은 생각. 감사. –
@CasparAleksanderBangJespers 도움을 주어 기쁘게 생각합니다! –