SVProgressHUD에 UITapGestureRecognizer를 추가해야합니다. SVProgressHUD는 이미 -(void) dismiss;
을 사용하여 닫을 수 있습니다. 이 코드는 초 단위로 애니메이션을 닫습니다.탭 제스처로 SVProgressHUD 닫기
- (void)dismiss {
for (UIGestureRecognizer *gesture in [[[self class] sharedView] gestureRecognizers]) {
[[[self class] sharedView] removeGestureRecognizer:gesture];
}
NSDictionary *userInfo = [self notificationUserInfo];
[[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDWillDisappearNotification
object:nil
userInfo:userInfo];
self.activityCount = 0;
[UIView animateWithDuration:0.15
delay:0
options:UIViewAnimationCurveEaseIn | UIViewAnimationOptionAllowUserInteraction
animations:^{
self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 0.8, 0.8);
if(self.isClear) // handle iOS 7 UIToolbar not answer well to hierarchy opacity change
self.hudView.alpha = 0;
else
self.alpha = 0;
}
completion:^(BOOL finished){
if(self.alpha == 0 || self.hudView.alpha == 0) {
self.alpha = 0;
self.hudView.alpha = 0;
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self cancelRingLayerAnimation];
[self addTapGestureToDismiss];
[_hudView removeFromSuperview];
_hudView = nil;
[_overlayView removeFromSuperview];
_overlayView = nil;
[_indefiniteAnimatedView removeFromSuperview];
_indefiniteAnimatedView = nil;
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);
[[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDDidDisappearNotification
object:nil
userInfo:userInfo];
// Tell the rootViewController to update the StatusBar appearance
UIViewController *rootController = [[UIApplication sharedApplication] keyWindow].rootViewController;
if ([rootController respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
[rootController setNeedsStatusBarAppearanceUpdate];
}
// uncomment to make sure UIWindow is gone from app.windows
//NSLog(@"%@", [UIApplication sharedApplication].windows);
//NSLog(@"keyWindow = %@", [UIApplication sharedApplication].keyWindow);
}
}];
}
내 생각 과정은 기각 방법에 tapGesture 코드를 추가하는 것입니다. 이것은 내가 지금까지 쓴 것입니다. 당신이 난 그냥 tapGesture를 초기화하고 있습니다 볼 수 있듯이
- (void)addTapGestureToDismiss {
// Creation and initializer of the tap gesture
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(dismiss)];
// Specify that the gesture must be a single tap
tapRecognizer.numberOfTapsRequired = 1;
// Add the tap gesture recognizer to the view
[[[self class] sharedView] addGestureRecognizer:tapRecognizer];
}
. 몇 군데에 배치하고 앱에 하나의 탭 만있는 문제가 발생했습니다. 나는 그 과정에서 자신을 혼란스럽게 만들었다. 해야할까요
- 이 제스처를보기에 추가해야합니까?
- 이 제스쳐를 추가 하시겠습니까? 나는이 솔루션 우연히이 질문을 기억 잠시 후
이 부분을 자세히 살펴본 후 이미지를 보여주는 코드를 발견했습니다. 나는 작은 테스트 코드를 구현했다 :'if (self.imageView) { self.dismiss; }'이 테스트 코드를 구현 한 후 HudImage는 즉시 공개되었습니다. 그래서 지금 제 질문은 _objec-c_에서 제스처에 대한 if 문을 작성하는 방법입니다. 사용자가 탭을 시작하면이를 무시하고 말할 필요가 있습니다. – MyloTut