我想在pageviewcontroller.m文件中实现-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 手势委托,但无法获得任何手势,如下所示:
NSArray *temp = self.gestureRecognizers;
NSLog(@"count %i",temp.count); // this logs count 0
NSArray *temp = self.view.gestureRecognizers;
NSLog(@"count %i",temp.count); // this also logs count 0
for (UIGestureRecognizer *gR in temp) {
gR.delegate = self;
}在上面的代码中,self指向pageviewcontroller。
因此,我不能将委托分配给pageviewcontroller手势。
编辑部分:
好的,我明白了,因为uipageviewscroll滚动样式,我没有得到任何手势对象。
但是我遇到了一个问题,我需要禁用pageviewcontroller pan手势,并且需要从两个按钮滚动页面视图控制器,就像用户尝试使用pan一样,它的起点在我的buttons框架内,否则页面视图控制器就不应该滚动。
我使用的是UIPageViewControllerTransitionStyleScroll. transitionStyle
任何解决办法..。提前感谢
发布于 2014-03-11 05:46:09
在尝试了这么多黑客之后,我终于找到了解决方案。
我所做的,首先得到了一个属性中的property控制器scorll视图。
for (UIView *view in mypageviewcontroller.view.subviews) {
if([view isKindOfClass:[UIScrollView class]])
{
pagescrollview= (UIScrollView *)view;
}
}然后将pan手势分配给页面视图控制器、藐视视图和手势委托。
UIPanGestureRecognizer* g1 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(gesture)];
[g1 setDelegate:self];
[pagescrollview addGestureRecognizer:g1];然后在手势委托中,我检查手势是否从我的愿望点开始,如果从应该滚动页面视图控制器的位置开始,则该委托方法应该返回no以启用原始的分页视图手势来接收pan手势。
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
CGPoint touchPoint = [touch locationInView:self.view];
if(floor(NSFoundationVersionNumber)<=NSFoundationVersionNumber_iOS_6_1)
touchPoint.y -=44;
else
touchPoint.y -=64;
PGNavigationController *nav =ViewControllerArray[VisiblePageindex];
PageContentVC *pagecontentvc = ((PageContentVC *) nav.visibleViewController);
if (touchPoint.y > pagecontentvc.leftpanalbtn.frame.origin.y && (pagecontentvc.leftpanalbtn.frame.size.height+pagecontentvc.leftpanalbtn.frame.origin.y )>touchPoint.y && touchPoint.x >pagecontentvc.leftpanalbtn.frame.origin.x
&& touchPoint.x<(pagecontentvc.leftpanalbtn.frame.origin.x+pagecontentvc.leftpanalbtn.frame.size.width)) {
return NO;
}
else if (touchPoint.y > pagecontentvc.rightpanalbtn.frame.origin.y && (pagecontentvc.rightpanalbtn.frame.size.height+pagecontentvc.rightpanalbtn.frame.origin.y )>touchPoint.y && touchPoint.x >pagecontentvc.rightpanalbtn.frame.origin.x
&& touchPoint.x<(pagecontentvc.rightpanalbtn.frame.origin.x+pagecontentvc.rightpanalbtn.frame.size.width))
{
return NO;
}
if( touchPoint.y>282 && touchPoint.x>118 &&touchPoint.y<282+75 && touchPoint.x < 118+85)
{
return NO;
}
// else if()
}
return YES;
}希望它能帮到别人。
https://stackoverflow.com/questions/21927970
复制相似问题