How can I access a uiview cusom property like tag on tap gesture in Objective-C?

172 Views Asked by At

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;
1

There are 1 best solutions below

1
cbiggin On

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.