3

Actually i want to do animation in objective.I have added list of imageview(subclassed) to view and stored all imageView in Array as following

    CustomImageView *imageView = [[CustomImageView alloc]init];
    imageView.tag = index;
    imageView._x = (i%4)*150;
    imageView._y = int(i/4)*150;
    imageView.vx = 0;
    imageView.vy = 0;
    imageView.dragging = false;
    imageView.frame = CGRectMake(imageView._x, imageView._y, imageView._width, imageView._height);
    imageView.userInteractionEnabled = YES;

    UITapGestureRecognizer *tapGesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(tapGesture:)];

    tapGesture1.numberOfTapsRequired = 1;

    [tapGesture1 setDelegate:self];

    [imageView addGestureRecognizer:tapGesture1];

    [self.view addSubview:imageView];

    [imageViewsArray  addObject:imageView];

can we access to change values of specific imageView property(subclass property) by following code

UIImageView * imageView = [imageViewsArray objectAtIndex:tag];
imageView.dragging = true;
imageView.vx = 0;
imageView.vy = 0;
Gopik
  • 255
  • 2
  • 17
  • 1
    You can cast the gestures view when it calls the action method – Wain Jan 19 '16 at 20:14
  • Thanks, so UIImageView * imageView refers to already added imageView in view? UIImageView *imageView = (UIImageView *)[sender view]; NSLog(@"tm%ld",(long)tmp.tag); and also i need to refer a specific imageView of list of imageView on Timer function. Cant we refer it with UIImageView * imageView = [imageViewsArray objectAtIndex:tmp.tag]; ?? – Gopik Jan 19 '16 at 20:17
  • I have no idea what tmp is.. – Wain Jan 19 '16 at 20:23
  • Please check the edited code. tmp refers here imageView. – Gopik Jan 19 '16 at 20:25

1 Answers1

0

Hmmm... um yes, it would work I think.

Not quite sure what you're trying to do here (especially given your x/y being based on the index), but in general instead of creating a CustomImageView for each image (which you would then have to insert into the view hierarchy), perhaps load the images (i.e., a UIImage) into your array instead and THEN swap them into your CustomImageView.

cbiggin
  • 1,942
  • 1
  • 17
  • 18
  • Actually i need to do drag option and floating animation , for that i need to refer a specific image (imageView) in list of images on Timer function(custom drawing every frame). Can't we refer it with UIImageView * imageView = [imageViewsArray objectAtIndex:tag]; (not using gesture event) – Gopik Jan 19 '16 at 20:30