Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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
Ios 如何将多个UIImageView添加到分页UIScrollView?_Ios_Xcode_Uiscrollview_Uiimageview_Uiimage - Fatal编程技术网

Ios 如何将多个UIImageView添加到分页UIScrollView?

Ios 如何将多个UIImageView添加到分页UIScrollView?,ios,xcode,uiscrollview,uiimageview,uiimage,Ios,Xcode,Uiscrollview,Uiimageview,Uiimage,我有一个启用分页的UIScrollView,页面上有多个子视图:UIButton、UIwebview和UIImageView。网页视图和图像在每个页面上都会发生变化。这个很好用。我用苹果来开始 但是,当我添加第二个UIImageView时,我所在的图像位置已经获得了新的值,并且新图像不会显示 这是viewdidload中用于第一个图像的代码(工作正常): 这是第二个图像的代码(inside viewdidload):(当我删除[self-layoutNavScrollImages]时;图像仅在第

我有一个启用分页的UIScrollView,页面上有多个子视图:UIButton、UIwebview和UIImageView。网页视图和图像在每个页面上都会发生变化。这个很好用。我用苹果来开始

但是,当我添加第二个UIImageView时,我所在的图像位置已经获得了新的值,并且新图像不会显示

这是viewdidload中用于第一个图像的代码(工作正常):

这是第二个图像的代码(inside viewdidload):(当我删除[self-layoutNavScrollImages]时;图像仅在第一页加载)


方法是创建一个(大)UIView,并将每个UIImageView添加为该UIView的子视图。然后将UIView作为子视图添加到UIScrollView

[totalView addSubview:imageView1];
[totalView addSubview:imageView2;
[totalView addSubview:buttonView1];
[totalView addSubview:buttonView2];
[totalView addSubview:webView];

[scrollView addSubview:totalView];
请确保设置正确的内容大小,否则scrollview将无法工作:

[scrollView setContentSize:CGSizeMake((320*kNumImages), 411)];
设置视图并标记UIView(内部视图加载):


我希望这一点尽可能清楚。如果有人认为这样做不对,请发表评论。

为什么要删除[self-layoutNavScrollImages];?我没有删除它,只是说:当我删除它时,图像将正确加载到一个页面上。我需要一种方法,使每一页上的图像加载,仍然有页面切换动画。尚未找到解决方案,但一个解决办法,将通过添加一个标签,而不是一个图像作为背景的imageview的这个特定项目的工作。myLabel.backgroundColor=[UIColor-WithPatternImage:[UIImage-ImageName:@“navigationbar.png”];然后在layoutNavScrollImages中将UIImageView更改为UILabel:-(void)layoutNavScrollImages{UILabel*view=nil;等等。。。
for (i = 1; i <= kNumImages; i++)
{

    UIImage *navBarImage = [UIImage imageNamed:@"navigationbar.png"];
    UIImageView *imageViewNavBar = [[UIImageView alloc] initWithImage:navBarImage];

    // setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
    CGRect navBarRect = imageViewNavBar.frame;
    navBarRect.size.height = 44;
    navBarRect.size.width = 320;
    navBarRect.origin.x = 0;
    navBarRect.origin.y = 0;

    /* Get the Layer of any view
     CALayer * imageLayer = [imageView3 layer];
     [imageLayer setMasksToBounds:YES];
     [imageLayer setCornerRadius:7.0];

     // You can even add a border
     [imageLayer setBorderWidth:1.0];
     [imageLayer setBorderColor:[[UIColor lightGrayColor] CGColor]];
     */
    imageViewNavBar.frame = navBarRect;
    imageViewNavBar.tag = i;    // tag our images for later use when we place them in serial fashion  

    [scrollView1 addSubview:imageViewNavBar];

}

[self layoutNavScrollImages];
- (void)layoutNavScrollImages
{
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)];
}
[totalView addSubview:imageView1];
[totalView addSubview:imageView2;
[totalView addSubview:buttonView1];
[totalView addSubview:buttonView2];
[totalView addSubview:webView];

[scrollView addSubview:totalView];
[scrollView setContentSize:CGSizeMake((320*kNumImages), 411)];
NSUInteger i;
for (i = 1; i <= kNumImages; i++)
   {
      //... code to setup views
      totalView.tag = i;
   }
[self layoutViews]; // now place the views in serial layout within the scrollview
- (void)layoutViews
{
UIView *view = nil;
NSArray *subviews = [scrollView subviews];

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

        curXLoc += (kScrollObjWidth);
    }
}
}