【发布时间】:2016-09-01 03:28:10
【问题描述】:
我需要将 UITapGestureRecognizer 添加到 SVProgressHUD。 SVProgressHUD 已经可以使用-(void) dismiss; 关闭。用于此的代码将基于秒关闭动画。
- (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 代码添加到dismiss方法中。这是我到目前为止所写的。
- (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];
}
如您所见,我只是在初始化 tapGesture。我遇到了将其放置在几个地方并导致应用程序只有一次点击的问题。在这个过程中,我几乎把自己弄糊涂了。我应该
- 将此手势添加到视图中?
- 添加此手势以关闭?
【问题讨论】:
-
仔细查看后,我找到了显示图像的代码。我实现了一些小的测试代码:
if (self.imageView ) { self.dismiss; }在实现了这个测试代码之后,HudImage 在显示出来后立即消失了。所以我现在的问题是,如何为 objec-c 中的手势编写 if 语句。我需要说,如果用户发起点击,请忽略这个?
标签: ios objective-c mobile uiviewcontroller svprogresshud