Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.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的Z位置_Ios_Objective C_Uiscrollview_Uiimageview - Fatal编程技术网

Ios UIImageView到UIScrollView的Z位置

Ios UIImageView到UIScrollView的Z位置,ios,objective-c,uiscrollview,uiimageview,Ios,Objective C,Uiscrollview,Uiimageview,我有两个UIScrollView和另一个UIImageView。我想让UIImageView越过UIScrollView。我已经尝试了所有的将subviewTofront和insertAtIndex功能,但都不起作用。请帮帮我 这是代码- 对于UIScrollView: UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 300,

我有两个
UIScrollView
和另一个
UIImageView
。我想让
UIImageView
越过
UIScrollView
。我已经尝试了所有的
将subviewTofront
insertAtIndex
功能,但都不起作用。请帮帮我

这是代码-

对于
UIScrollView

UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 300,
                                                  SCREEN_WIDTH, SCREEN_HEIGHT)];
scrollView.showsHorizontalScrollIndicator = FALSE;
[self.view addSubview:scrollView];

__block int tagValue = 1;
__block NSInteger tag = 1;

for (int i=0; i<[listOfImages count]; i++) {
    NSDictionary *myDic = [listOfImages objectAtIndex:i];
    NSString *urlImage = [myDic objectForKey:@"product_image"];
    //NSLog(@"%lu",(unsigned long)[listOfImages count]);
    image = [[UIImageView alloc] initWithFrame:CGRectMake(leftMargin, 0, 200, 140)];
    // [image setImage:[UIImage imageNamed:@"img_def.png"]];
    NSURL *imageURL = [NSURL URLWithString:urlImage];

    [image setImageWithURL:imageURL 
          placeholderImage:[UIImage imageNamed:@"img_def.png"]];

    image.tag = tag;
    image.contentMode = UIViewContentModeScaleAspectFit;

    [scrollView insertSubview:image atIndex:1];
    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] 
                             initWithTarget:self action:@selector(handleTap:)];
    recognizer.numberOfTapsRequired = 1;
    recognizer.numberOfTouchesRequired = 1;
    recognizer.delegate = self;
    [image addGestureRecognizer:recognizer];
    [image setUserInteractionEnabled:YES];

    leftMargin += SCREEN_WIDTH;
    tagValue += 1;
    tag += 1;

}
[scrollView setContentSize:CGSizeMake(leftMargin, 0)];
[scrollView setPagingEnabled:YES];

不要使用
insertSubview:atIndex
而是使用
addSubview:
。添加子视图时,它始终添加在父视图中已存在的所有其他子视图的顶部

UIImage *originalPromo = [UIImage imageNamed:@"promo"];
    UIImage *scaledPromo = [UIImage imageWithCGImage:[originalPromo CGImage] 
     scale:(originalPromo.scale *2.0) orientation:(originalPromo.imageOrientation)];
    UIImageView *promo = [[UIImageView alloc] init];
    [promo setFrame:CGRectMake(45.5, 300.0, 
                               scaledPromo.size.width, scaledPromo.size.height)];
    [promo setImage:scaledPromo];
    [self.view insertSubview:promo atIndex:100];