在UIPageViewControllerDataSource中使用UITapGestureRecognizer无法正常工作

时间:2014-09-14 17:54:16

标签: ios ios7 xcode5 uipageviewcontroller uitapgesturerecognizer

我一直在尝试添加UITapGestureRecognizer,以便可以使用UIPageViewControllerDataSource中的按钮更改视图。

我添加了子类

@interface OverallViewController : UIViewController <UIPageViewControllerDataSource,UIGestureRecognizerDelegate>
@property (strong, nonatomic) UIPageViewController *pageController;

页面导航对我来说很好但是在viewDidLoad中尝试以下UITapGestureRecognizer时我什么都没得到

UIView *topbar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 52)];
    topbar.backgroundColor = [UIColor colorWithRed:(245/255.0) green:(245/255.0) blue:(245/255.0) alpha:1];
    left = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nav-profile-sm.png"]];
    left.frame = CGRectMake(15, 15, 25, 25);
    //End add top nav


    [topbar addSubview:left];
    [self.view addSubview:topbar];

    //Add top navigation gestures
    UITapGestureRecognizer *profiletap = [[UITapGestureRecognizer alloc]
                                   initWithTarget:self
                                   action:@selector(profileButtonTap)];
    profiletap.numberOfTapsRequired = 1;

    profiletap.delegate = self;

    [left addGestureRecognizer:profiletap];

此处无响应

-(void) profileButtonTap {
NSLog(@"Profile button tapped");
}

当我尝试覆盖gestureRecognizer时没有任何内容

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    CGPoint touchPoint = [touch locationInView:touch.view];
    NSLog(@"Touch: %f,%f", touchPoint.x, touchPoint.y);
        if (touchPoint.y < 52) {
            return NO; // ignore the touch
        }

    return YES; // handle the touch
}

当我说我得不到任何东西时我的意思是没有记录任何东西,这些方法似乎没有被调用,我不确定如何进一步解决或调试。感谢您的任何帮助,想法和建议!

0 个答案:

没有答案