我有UIScrollView
和另一个UIImageView
。我希望UIImageView
超过UIScrollView
。我已经尝试了所有bringSubviewToFront
和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];
我希望在滚动视图之上的图像代码 -
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];
答案 0 :(得分:0)
而不是使用insertSubview:atIndex
使用addSubview:
。添加子视图时,它总是添加在父视图中已有的所有其他子视图之上。