Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.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
iphone UIScrollView反向顺序定位_Iphone_Uiscrollview_Reverse - Fatal编程技术网

iphone UIScrollView反向顺序定位

iphone UIScrollView反向顺序定位,iphone,uiscrollview,reverse,Iphone,Uiscrollview,Reverse,我正在基于苹果提供的“滚动”示例代码构建一个应用程序。一切都很顺利。如果图像的顺序颠倒,并且第一个可见的图像是最右边的,而不是最左边的,那么我想要显示的图像的性质将使它成为可取的。基本上,用户应该从右向左滚动,而不是从左向右滚动。 但现在:我不明白苹果使用的语法,我希望有人能向我解释到底发生了什么。以下是示例应用程序的相关部分: - (void)viewDidLoad { self.view.backgroundColor = [UIColor whiteColor]; //

我正在基于苹果提供的“滚动”示例代码构建一个应用程序。一切都很顺利。如果图像的顺序颠倒,并且第一个可见的图像是最右边的,而不是最左边的,那么我想要显示的图像的性质将使它成为可取的。基本上,用户应该从右向左滚动,而不是从左向右滚动。 但现在:我不明白苹果使用的语法,我希望有人能向我解释到底发生了什么。以下是示例应用程序的相关部分:

- (void)viewDidLoad
{
    self.view.backgroundColor = [UIColor whiteColor];

    // load all the images from our bundle and add them to the scroll view
    NSUInteger i;
    for (i = 1; i <= kNumImages; i++)
    {
        NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];
        UIImage *image = [UIImage imageNamed:imageName];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

        // setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
        CGRect rect = imageView.frame;
        rect.size.height = kScrollObjHeight;
        rect.size.width = kScrollObjWidth;
        imageView.frame = rect;
        imageView.tag = i;  // tag our images for later use when we place them in serial fashion
        [scrollView1 addSubview:imageView];
        [imageView release];
    }

    [self layoutScrollImages];  // now place the photos in serial layout within the scrollview

}

- (void)layoutScrollImages
{
    UIImageView *view = nil;
    NSArray *subviews = [scrollView1 subviews];

    // reposition all image subviews in a horizontal serial fashion
    CGFloat curXLoc = 0;
    for (view in subviews)
    {
        if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
        {
            CGRect frame = view.frame;
            frame.origin = CGPointMake(curXLoc, 0);
            view.frame = frame;

            curXLoc += (kScrollObjWidth);
        }
    }

    // set the content size so it can be scrollable
    [scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
}
-(void)viewDidLoad
{
self.view.backgroundColor=[UIColor whiteColor];
//从我们的包中加载所有图像,并将它们添加到滚动视图中
NSUI;
对于(i=1;i 0)
{
CGRect frame=view.frame;
frame.origin=CGPointMake(curXLoc,0);
view.frame=frame;
curXLoc+=(kScrollObjWidth);
}
}
//设置内容大小,使其可以滚动
[scrollView1 setContentSize:CGSizeMake((kNumImages*kScrollObjWidth),[scrollView1 bounds].size.height];
}

看起来您需要修改LayoutScrollImage。将curXLoc初始化为所需的最大值,并在循环中递减

- (void)layoutScrollImages
{
    UIImageView *view = nil;
    NSArray *subviews = [scrollView1 subviews];

    // reposition all image subviews in a horizontal serial fashion
    CGFloat curXLoc = kNumImages * kScrollObjWidth;
    for (view in subviews)
    {
        if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
        {
                CGRect frame = view.frame;
                frame.origin = CGPointMake(curXLoc, 0);
                view.frame = frame;

                curXLoc -= (kScrollObjWidth);
        }
    }

    // set the content size so it can be scrollable
    [scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
}

这就是我最后要做的: 我首先颠倒了子视图的顺序,然后通过添加以下行使scrollview跳转到最后一个“帧”:

CGPoint lastFrame = CGPointMake(((kNumImages -1) * kScrollObjWidth), 0.0f);
[scrollview setContentOffset:lastFrame];

我希望这对某些人有用…

你对语法的哪一部分有问题?基本上是CG相关的东西。我试图更改“for(I=1;I 1;I--)”,但在我的应用程序上下文中,这带来了意想不到的结果。除此之外,它不能解决我关于如何显示最后一个最右边的“帧”的问题。谢谢你的建议。不幸的是,它不起作用,因为我仍在试图理解代码这一部分中发生了什么,所以我也无法进行故障排除。不过,我更接近于解决方案:我只是在代码中的其他地方恢复了子视图的顺序。现在唯一剩下的就是将scrollView1作为最后一个子视图,而不是第一个子视图。