0

I am new for CAShapeLayer.In my application I am showing subjects (CAShapeLayer) in scrollview.When user click on subject i want to show exams and set content size of scrollview.I am finding touch point and and then comparing with each subject.If match,show exams.When i click on subject and try to change position,it is showing me twice,while i am adding only once.Here is code of my touch event:

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


    }
}
}
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
user007
  • 69
  • 8
  • Welcome to stack overflow. Please don't make useless changes to your question (like adding “Please help me...” and “Waiting for reply.”) to draw more attention to your question. Instead, try to make your question more clear, easier to understand. I guess English is not your first language, and that is ok, but I don't understand what you mean by “it is showing me twice”. What is it showing twice? – rob mayoff Jun 26 '13 at 04:23
  • yes you are right @robmayoff , here i am showing subjects using CAShapeLayer.If user clicks on subject i need to show exams under that subject.And as exams has taken place between two subjects so i want to move down other subjects.i did it by changing position.But when i am changing position , it is creating second copy of subjects which is moving down and first copy staying as it is. – user007 Jun 26 '13 at 04:38
  • 1
    I don't know what's wrong with your code. I can tell you that overall your code would probably be simpler to understand, and work better, if you used a `UITableView` instead of a `UIScrollView`, making each subject one row. You can add the exams into the currently selected cell, making the cell dynamically taller as needed. [This answer](http://stackoverflow.com/a/2063776/77567) contains the secret incantation you need to animate changes to a table view row's height. – rob mayoff Jun 26 '13 at 04:51
  • that is what i am thinking.i want to just change position of cashapelayer,it is moving also but it is not removing from first position.It is look like creating second copy of subjects. – user007 Jun 26 '13 at 05:23

0 Answers0