如何为从服务器检索到的多个图像添加滑动手势。 我从server.how得到str = @“but1.jpg,but2.jpg”,用swipe显示这些图像存储在字符串中。 对于从服务器显示的单个图像我从服务器获得基于键“image_names”的响应,我将它存储在string.my代码如下
url=@"http:..........";
str=[dict1 valueForKey:@"image_names"];
if (str!=nil) {
strImg=[url stringByAppendingString:str];
dispatch_async(dispatch_get_global_queue(0,0), ^{
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:strImg]];
if ( data == nil )
return;
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *img=[UIImage imageWithData: data];
imgView.image=img;
});
});
}
答案 0 :(得分:0)
我不知道你究竟是什么问题,但你可以在任何图像上添加滑动手势,如下面的代码行。
UISwipeGestureRecognizer *swipeLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftGesture:)];
UISwipeGestureRecognizer *swipeRightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightGesture:)];
[swipeLeftGesture setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeRightGesture setDirection:UISwipeGestureRecognizerDirectionRight];
// Adding the both the swipe gesture to UIImageview
[imageView addGestureRecognizer:swipeLeftGesture];
[imageView addGestureRecognizer:swipeRightGesture];