1

I've this code:

int i=0;
for (UIView *view in [self subviews]) {
   //NSLog(@"index %d - i %d",index,i);
   if (i==index) {
      NSLog(@"index %d - i %d",index,i);
      [view setAlpha:0.3];
      [view setUserInteractionEnabled:NO];
   }
   i++;
}

"index" is a variable used to select the view to modify.

The problem is that nothing happen, instead if I run this code:

for (UIView *view in [self subviews]) {
    [view setAlpha:0.3];
    [view setUserInteractionEnabled:NO];
}

every view will be modify obviously, but i need the first code :)

ideas?

4

2 回答 2

1

设置滚动视图中所有子视图的标签,然后将所选视图的标签传递给索引变量,希望它是一个整数

 for(int i = 1; i <=4; i++){

  UIView *myView =  [UIView......]; // set your view
  myView.tag  = i;
  [your_scrollView addSubview:myView];
}

然后你可以像下面这样。

for (UIView *view in [your_scrollView subviews])
{
  if (view.tag == index) 
  {
  [view setAlpha:0.3];
  [view setUserInteractionEnabled:NO];
  }
}

或者有一种简单的方法来获取视图 [your_scrollView viewWithTag:index]

于 2013-01-09T14:39:31.153 回答
0

Try this code :-

for (UIView *view in [scrollView subviews]) {
        [view setAlpha:0.3];
        [view setUserInteractionEnabled:NO];
    }

Hope it works

于 2013-01-09T14:30:32.470 回答