我们如何限制iphone sdk中的手势属性?

时间:2011-11-10 12:41:25

标签: iphone

哈,我正在做一个阅读器应用程序,里面有章节,我已经在tableview中完成了刷卡识别属性,用于重新加载tableview,下一页和前一章右键滑动以进行下一步和左键滑动。同时时间我在按钮点击中添加了相同功能的按钮,问题是当章节结束时,这意味着书只包含9章,如果我到达第9章,右边的滑动属性必须停止,反之亦然。但我已经完成了它在按钮中通过禁用按钮,如果第9章loda它自动禁用按钮,所以用户没有点击按钮,我想在我的滑动左右功能相同的方法>如何做到这一点这是我的刷卡代码

UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
    swipeGesture.direction = UISwipeGestureRecognizerDirectionRight; // or whatever
    [table addGestureRecognizer:swipeGesture];
    [swipeGesture release];
    UISwipeGestureRecognizer *swipeGestureleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGestureleft:)];
    swipeGestureleft.direction = UISwipeGestureRecognizerDirectionLeft; // or whatever
    [table addGestureRecognizer:swipeGestureleft];
    [swipeGestureleft release];
-(void) handleSwipeGesture:(UISwipeGestureRecognizer*)recognizer {

    delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] + 1];
    [delegate reloadVerses];
    [self resetReadViewToVerse:1]; 
}

EDIT :::      - (void)handleSwipeGestureleft:(UISwipeGestureRecognizer *)识别器{

    delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] - 1];
    [delegate reloadVerses];
    [self resetReadViewToVerse:1]; 
}

这是我隐藏按钮或禁用按钮的方法,我想停止并启动手势。请帮助我。 提前致谢。 提前致谢。 修改

-(void)resetReadViewToVerse:(int)verseNo;
{
    if(![delegate.selectedChapter isEqualToString:@"1"])
    {
        previousButton.enabled = YES; 
        table.tableHeaderView =previousButton;


    }
    else
    {
        previousButton.enabled = NO;
        table.tableHeaderView =nil;

    }

    if(![delegate.selectedChapter isEqualToString:[NSString stringWithFormat:@"%d",[DbHandler mNumberOfChaptersInBook:delegate.selectedBook]]])
    {
        nextButton.enabled =YES;
        table.tableFooterView =nextButton;


    }
    else
    {
        nextButton.enabled = NO;
        table.tableFooterView =nil;

    }
    -(void) handleSwipeGesture:(UISwipeGestureRecognizer*)recognizer {


     if(![delegate.selectedChapter isEqualToString:[NSString stringWithFormat:@"%d",[DbHandler mNumberOfChaptersInBook:delegate.selectedBook]]]) {
        // if the currentChapter is the last then do nothing
         delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] + 1];
         [delegate reloadVerses];
         [self resetReadViewToVerse:1];
    }
    return;



}
-(void) handleSwipeGestureleft:(UISwipeGestureRecognizer*)recognizer {

    if(![delegate.selectedChapter isEqualToString:@"1"])
    {
        delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] - 1];
        [delegate reloadVerses];
        [self resetReadViewToVerse:1]; 
    }
    return;


}

1 个答案:

答案 0 :(得分:1)

您无需停用手势,只需检查selectedChapter + 1是否不超过章节总数,如果您忽略该手势。

编辑:

你可以这样做(假设你可以询问代表totalNumberOfChapters):

-(void) handleSwipeGesture:(UISwipeGestureRecognizer*)recognizer {

    // delegate.selectedChapter should be NSInteger, would be easier

    NSInteger currentChapter = [delegate.selectedChapter integerValue];

    if (currentChapter >= delegate.totalNumberOfChapters) {
        // if the currentChapter is the last then do nothing
        return;
    }

    delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] + 1];
    [delegate reloadVerses];
    [self resetReadViewToVerse:1]; 
}