objective c - Issue with scroll view and accessing its subviews -


i have scroll view contains image view sized 68x78:

enter image description here

as see, images except centered 1 have shadow. changes when user scrolls, center image clear. goes perfect until left edge image:

enter image description here

here code:

-(void) buildslideview{      fotosjugadores = [[nsarray alloc] initwithobjects:@"cara5.png", @"cara7.png", @"cara8.png", @"cara9.png", @"cara11.png", @"cara13.png", @"cara14.png", @"cara15.png", @"cara18.png",@"cara19.png", @"cara20.png", @"cara32.png",@"cara44.png",@"cara51.png", @"cara100.png", @"cara101.png", @"cara102.png",@"cara103.png", @"cara104.png", @"cara105.png",@"cara106.png",@"cara107.png", nil];      numberofviews = [fotosjugadores count];      (int = 0; <    [fotosjugadores count]; i++) {          uiimage *myimage = [uiimage imagenamed:[fotosjugadores objectatindex:i]];         cgfloat yorigin = * (myimage.size.width+3) + 120;         uiimageview *awesomeview = [[uiimageview alloc] initwithframe:cgrectmake(yorigin, 0, myimage.size.width, myimage.size.height)];         awesomeview.tag = i;         awesomeview.image = myimage;         awesomeview.alpha = 0.5f;         awesomeview.backgroundcolor = [uicolor blackcolor];         [self.jugadorslide addsubview:awesomeview];         awesomeview=nil;      }      [jugadorslide setbackgroundcolor:[uicolor blackcolor]];     jugadorslide.contentsize = cgsizemake(68 * numberofviews+240,78);     jugadorslide.layer.cornerradius = 11;     jugadorslide.layer.maskstobounds = yes;     [jugadorslide setcontentoffset:cgpointmake(((68 * numberofviews)/2), 0)];     //jugadorslide.decelerationrate = uiscrollviewdecelerationratenormal;     [self scrollviewdidenddragging:jugadorslide willdecelerate:no];  }  - (void)scrollviewdidenddragging:(uiscrollview *)scrollview willdecelerate:(bool)decelerate {     currentindex = roundf(scrollview.contentoffset.x / 68);     nslog(@"current end %d", currentindex);     uiimageview *currentimage = [scrollview viewwithtag:currentindex];     if (currentindex>0&&currentindex<=21){          if (currentindex==currentimage.tag){             currentimage.alpha=1.0f;             [self changeperfilimage:currentimage.tag];}              cgpoint pointzero= cgpointmake(scrollview.contentoffset.x, currentimage.frame.origin.y);             [jugadorslide setcontentoffset:pointzero animated:yes];      }else {             uiimageview *currentimage = [scrollview viewwithtag:0];             nslog(@"end dragging image tag %d", currentimage.tag);             currentimage.alpha=1.0f;             [self changeperfilimage:currentimage.tag];}             cgpoint pointzero= cgpointmake(currentimage.frame.origin.x+15, 0);             //[jugadorslide setcontentoffset:pointzero animated:yes];  } 

as can see, in scrollviewdidenddragging: "else" , forced tag desesperate solution, images doesn't clear.

you incrementing tag twice...

awesomeview.tag = i++; 

should be:

awesomeview.tag = i+1; 

i use i+1 because never use tag of 0 since subview hasn't been assigned tag have tag of 0.

- (void)scrollviewdidenddragging:(uiscrollview *)scrollview willdecelerate:(bool)decelerate {     nsinteger currentindex = roundf(scrollview.contentoffset.x / 68.0) + 1;     uiimageview *currentimage = [scrollview viewwithtag:currentindex];     ... } 

if doesn't work should nslog currentindex each time land on new image , see happening when land on first one.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -