我有一个视图控制器,它在实例化时加载一组图像。我有一个滑块用于选择要显示的图像。现在我想显示一个自定义滑块,其中包含用户可以点击的每个图像的预览。我尝试了一些代码,但每当我点击滑块中的图像时,它只显示来自服务器的数组的图像视图中的第一个图像,并且它不显示数组中的其他图像。我试过的代码是:
w = np.random.random(size)*2-1
w /= w.sum()
w
array([[ 0.05377353],
[ 0.11272973],
[ 0.00789277],
...,
[ 0.06874176],
[-0.12505825],
[-0.15924267]])
w.sum()
1.0
expand方法就是这样,
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSArray *arrayOfImages = [userDefaults objectForKey:@"property_images"];
NSLog(@"GGG %@",arrayOfImages);
self.imagesData=[[NSArray alloc]init];
self.imagesData = arrayOfImages;
NSLog(@"Image Array is %@",_imagesData);
dispatch_group_t group = dispatch_group_create();
for(int i=0; i<self.imagesData.count;i++){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.frame) * i, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.scrollView.frame))];
imageView.contentMode = UIViewContentModeScaleAspectFill;
// imageView.image = [UIImage imageNamed:[self.imagesData objectAtIndex:i]];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(expandImage:)];
tap.numberOfTapsRequired = 1;
tap.view.tag = i;
[imageView setUserInteractionEnabled:YES];
[imageView addGestureRecognizer:tap];
[self.scrollView addSubview:imageView];
dispatch_group_enter(group);
[imageView sd_setImageWithURL:[NSURL URLWithString:[self.imagesData objectAtIndex:i]] placeholderImage:nil options:SDWebImageHighPriority completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
dispatch_group_leave(group);
}];
_fullImage.hidden=NO;
_fullView.hidden=NO;
}
答案 0 :(得分:0)
在imageView.tag
上设置代码而不是tap.view.tag
。
当tap.view.tag
包含tap.view
值时,您正在设置nil
。