我希望有两个水龙头使其全屏,两个水龙头返回常规。但是,两个GestureRecognizer是冲突的,并且都被调用,导致屏幕不变。我该如何解决这个问题?
这是我的代码:
-(void) tap2Full {
//Teste apartir daqui "TAP"
UITapGestureRecognizer *fullScreen = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fullScreen)];
fullScreen.numberOfTapsRequired = 1;
UITapGestureRecognizer *screenOut = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(screenOut)];
screenOut.numberOfTapsRequired = 2;
// stops tapOnce from overriding tapTwice
[fullScreen requireGestureRecognizerToFail:screenOut];
fullScreen.delegate = self;
screenOut.delegate = self;
[self.webView addGestureRecognizer:fullScreen];
[self.webView addGestureRecognizer:screenOut];
}
- (void)fullScreen {
self.navigationController.navigationBar.layer.zPosition = -1;
[self.view bringSubviewToFront:self.webView];
self.webView.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
self.webView.layer.zPosition = 9;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)screenOut {
self.navigationController.navigationBar.layer.zPosition = 1;
self.webView.frame = CGRectMake(self.view.frame.origin.x, 113, 320, 455);
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
答案 0 :(得分:0)
我的代码已经改变了。请它希望这对你有用。
//Global BOOL flag
BOOL isTapOnScreen;
-(void) tap2Full {
isTapOnScreen = TRUE;
//Teste apartir daqui "TAP"
UITapGestureRecognizer *fullScreen = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fullScreen)];
fullScreen.numberOfTapsRequired = 2;
fullScreen.delegate = self;
[self.webView addGestureRecognizer:fullScreen];
}
- (void)fullScreen {
if(isTapOnScreen == FALSE) {
self.navigationController.navigationBar.layer.zPosition = 1;
self.webView.frame = CGRectMake(self.view.frame.origin.x, 113, 320, 455);
[[UIApplication sharedApplication] setStatusBarHidden:NO];
isTapOnScreen = TRUE;
}
else {
self.navigationController.navigationBar.layer.zPosition = -1;
[self.view bringSubviewToFront:self.webView];
self.webView.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
self.webView.layer.zPosition = 9;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
isTapOnScreen = FALSE;
}
}
谢谢.. :))
答案 1 :(得分:0)
以下是两种方法。第一个是仅使用一个手势,第二个是您需要删除并重新添加它们的位置。
使用此方法,您只使用一个gestureRecognizer:
@implementation YourController {
BOOL isFullScreen;
}
-(void) tap2Full {
isFullScreen = FALSE;
UITapGestureRecognizer *toggleScreen = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleScreen)];
toggleScreen.numberOfTapsRequired = 2;
toggleScreen.delegate = self;
[self.webView addGestureRecognizer:fullScreen];
}
- (void) toggleScreen {
if(isFullScreen) {
self.navigationController.navigationBar.layer.zPosition = 1;
self.webView.frame = CGRectMake(self.view.frame.origin.x, 113, 320, 455);
[[UIApplication sharedApplication] setStatusBarHidden:NO];
isFullScreen = FALSE;
} else {
self.navigationController.navigationBar.layer.zPosition = -1;
[self.view bringSubviewToFront:self.webView];
self.webView.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
self.webView.layer.zPosition = 9;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
isFullScreen = TRUE;
}
}
使用这种解决问题的方法,您将删除 当您不需要时,可以使用gestureRecognizers,并在您重新添加它们时重新添加它们 做。
您需要做的是在此处添加手势:
@implementation YourController {
UITapGestureRecognizer *fullScreen;
UITapGestureRecognizer *screenOut;
}
然后更改tap2F
:
fullScreen = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fullScreen)];
fullScreen.numberOfTapsRequired = 2;
screenOut = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(screenOut)];
screenOut.numberOfTapsRequired = 2;
然后修改fullScreen
:
- (void)fullScreen {
self.navigationController.navigationBar.layer.zPosition = -1;
[self.view bringSubviewToFront:self.webView];
self.webView.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
self.webView.layer.zPosition = 9;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self.webView removeGestureRecognizer: fullScreen];
for (UIGestureRecognizer* recognizer in self.webView.gestureRecognizers) {
if (![recognizer isEqual: screenOut]) {
[self.webView addGestureRecognizer: screenOut];
}
}
}
并更改screenOut
:
- (void)screenOut {
self.navigationController.navigationBar.layer.zPosition = 1;
self.webView.frame = CGRectMake(self.view.frame.origin.x, 113, 320, 455);
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[self.webView removeGestureRecognizer: screenOut];
for (UIGestureRecognizer* recognizer in self.webView.gestureRecognizers) {
if (![recognizer isEqual: fullScreen]) {
[self.webView addGestureRecognizer:fullScreen];
}
}
}