0

CAShapeLayerのアプリケーションでは、件名 ( CAShapeLayer) をスクロールビューに表示しています。ユーザーが件名をクリックすると、試験を表示し、スクロールビューのコンテンツサイズを設定したいと考えています。タッチポイントを見つけて、各件名と比較しています。一致する場合は、件名をクリックして位置を変更しようとすると、一度だけ追加している間に2回表示されます。タッチイベントのコードは次のとおりです。

- (void)singleTapGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer{
CGPoint touchPoint=[gestureRecognizer locationInView:self];
//take subviews of view
NSArray* subLayerArray = [self subLayerOfView];

BOOL showChildren = NO;
//compare touch point
for (int i = 0; i < subLayerArray.count; i++) {

    A3AddSubjectView* aAddSubject = [subLayerArray objectAtIndex:i];
    if (showChildren == YES) {
        int heightForSubject = 150*(i+1);
        aAddSubject.position = CGPointMake(aAddSubject.position.x, heightForSubject);
        aAddSubject.backgroundColor = [UIColor redColor].CGColor;
    }
    CGAffineTransform transf = CGAffineTransformMakeTranslation(-aAddSubject.position.x, - aAddSubject.position.y);
    if(CGPathContainsPoint(aAddSubject.path, &transf, touchPoint, NO)){
        if (aAddSubject.level == 0) {
            aAddSubject.level = 1;
        }
        else
            aAddSubject.level = 0;
        showChildren = YES;

        [self.delegate didSingleTapSubjectAtLevel:aAddSubject.level withIndex:i inView:self];
        NSDate* startDateOfSubject = [aAddSubject.startDate dateByAddingTimeInterval:19800];
        aAddSubject = [self.datasource selectSubjectAtLevel:aAddSubject.level withIndex:i inView:self];
        for (int j = 0; j < aAddSubject.children.count; j++) {
            NSMutableDictionary* dict = [aAddSubject.children objectAtIndex:j];
            NSDate* startDateOfExam = [[dict objectForKey:@"StartDate"] dateByAddingTimeInterval:19800];
            NSDate* endDateOfExam = [[dict objectForKey:@"EndDate"] dateByAddingTimeInterval:19800];
            int totalDaysBetweenExam = [self differenceBetweenTwoDatesFromDate:startDateOfExam toDate:endDateOfExam];
            CGFloat widthOfexam = totalDaysBetweenExam * dayWidth;
            //size
            CGSize sizeOfExam;
            sizeOfExam.width = widthOfexam;
            sizeOfExam.height = 10;
            //distance from origin
            int distanceFromOrigin = [self differenceBetweenTwoDatesFromDate:startDateOfSubject toDate:startDateOfExam] * dayWidth;
            A3ExamsView* aExamView = [[A3ExamsView alloc]init];
            [aExamView examWithTitle:[dict objectForKey:@"title"] withFont:[UIFont systemFontOfSize:20] withSize:sizeOfExam];
            aExamView.position = CGPointMake(distanceFromOrigin, 70*(j+1));
            [self.layer addSublayer:aExamView];
        }


    }
}
}
4

0 に答える 0