Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 滚动视图和访问其子视图时出现问题_Objective C_Ios5 - Fatal编程技术网

Objective c 滚动视图和访问其子视图时出现问题

Objective c 滚动视图和访问其子视图时出现问题,objective-c,ios5,Objective C,Ios5,我有一个滚动视图,其中包含大小为68x78的图像视图: 正如你所看到的,除了居中的图像外,所有的图像都有阴影。当用户滚动时它会改变,中心图像总是清晰的。对于左边缘图像,它非常完美: 代码如下: -(void) buildSlideView{ fotosJugadores = [[NSArray alloc] initWithObjects:@"cara5.png", @"cara7.png", @"cara8.png", @"cara9.png", @"cara11.png", @

我有一个滚动视图,其中包含大小为68x78的图像视图:

正如你所看到的,除了居中的图像外,所有的图像都有阴影。当用户滚动时它会改变,中心图像总是清晰的。对于左边缘图像,它非常完美:

代码如下:

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

    for (int i = 0; i <    [fotosJugadores count]; i++) {

        UIImage *myImage = [UIImage imageNamed:[fotosJugadores objectAtIndex:i]];
        CGFloat yOrigin = i * (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];

}
-(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”,“cara104.png”@“cara106.png”,@“cara107.png”,nil];
numberOfViews=[fotosJugadores计数];
for(int i=0;i<[fotosJugadores计数];i++){
UIImage*myImage=[UIImage ImageName:[fotosJugadores对象索引:i]];
CGFloat yOrigin=i*(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.addSubview:awesomeView];
awesomeView=nil;
}
[JugadorBackgroundColor:[UIColor blackColor]];
jugadorside.contentSize=CGSizeMake(68*numberOfViews+240,78);
jugadorSlide.layer.cornerRadius=11;
jugadorside.layer.masksToBounds=是;
[setContentOffset:CGPointMake((68*numberOfViews)/2),0];
//jugadorSlide.decelerationRate=UIScrollViewDecelerationRateNormal;
[自滚动视图DIDENDDRAGING:jugadorSlide将减速:否];
}
-(void)ScrollViewDiEndDraging:(UIScrollView*)scrollView将减速:(BOOL)减速{
currentIndex=roundf(scrollView.contentOffset.x/68);
NSLog(@“当前结束%d”,当前索引);
UIImageView*currentImage=[scrollView视图带标记:currentIndex];

如果(currentIndex>0&¤tIndex将标记增加两次

awesomeView.tag = i++;
应该是:

awesomeView.tag = i+1;
我使用I+1是因为我从不使用标记0,因为任何未指定标记的子视图都将具有标记0

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    NSInteger currentIndex = roundf(scrollView.contentOffset.x / 68.0) + 1;
    UIImageView *currentImage = [scrollView viewWithTag:currentIndex];
    ...
}

如果这不起作用,您应该在每次登录到新图像时记录currentIndex,并查看登录到第一个图像时发生的情况。

对不起,我编辑了它,I++是另一个尝试解决此问题的人。对于给您带来的不便,我深表歉意。我在代码中有NSLog,并且在执行过程中标记似乎是正确的。谢谢。无论如何,我投票您的兴趣是积极的。您是否尝试使用i+1(并将currentIndex增加1)?另外,记录当前图像,看看它是作为UIImage还是作为nil返回。我尝试了+1,但它将下一个图像移到中心。但当它获取标记为0的图像时,我打印了图像值说明,它得到:,因此它不是获取标记为0的第一个UIImage,而是获取偏移量。如果您增加了“currentIndex”“通过ScrollViewDiEndDraging方法中的1,那么它应该得到当前图像,而不是下一个图像。我对当前图像+1,对.tag分配+1,现在它可以工作了!谢谢!