如何向下移动CAShapeLayer?

时间:2013-06-25 10:29:25

标签: ios cashapelayer

我是CAShapeLayer的新用户。在我的应用程序中,我在scrollview中显示主题(CAShapeLayer)。当用户点击主题时,我想要显示检查并设置scrollview的内容大小。我找到了触摸点,然后与每个主题进行比较。如果匹配,则显示考试。当我点击主题并尝试更改位置时,它会向我显示两次,而我只添加一次。这是我的触摸事件的代码:

- (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];
        }


    }
}
}

0 个答案:

没有答案