我在單個視圖中製作了多個圖像拖動。在該應用中,只有一個視圖具有圖像。我希望能夠從左到右,從右到左滑動,並讓第一張圖片離開視圖,第二張圖片進入。我正在嘗試編碼。但它不適用於我。請任何身體指南我是新來的圖像swipping.Thanks提前。如何在ios的單個視圖中滑動多個圖像
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 190)];
scrollView.showsVerticalScrollIndicator=YES;
scrollView.userInteractionEnabled=YES;
scrollView.delegate = self;
scrollView.scrollEnabled = YES;
scrollWidth = 120;
scrollView.contentSize = CGSizeMake(scrollWidth,80);
[self.view addSubview:scrollView];
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *err;
NSString *strResponse=[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"response is %@",strResponse);
dict1=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&err];
NSLog(@"vals are %@",dict1);
NSString *strImg;
[email protected]"myimageurl";
str=[dict1 valueForKey:@"image_names"];
arrImages=[str componentsSeparatedByString:@","];
for(int index=0; index < [arrImages count]; index++)
{
NSLog(@"image: %@",[arrImages objectAtIndex:index]);
if (str!=nil)
{
strImg=[url stringByAppendingString:[arrImages objectAtIndex:index]];
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;
});
});
}
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [[event allTouches] anyObject];
for(int index=0;index<[arrImages count];index++)
{
UIImageView *imgView = [arrImages objectAtIndex:index];
NSLog(@"x=%f,y=%f,width =%f,height=%f",imgView.frame.origin.x,imgView.frame.origin.y,imgView.frame.size.width,imgView.frame.size.height);
NSLog(@"x= %f,y=%f",[touch locationInView:self.view].x,[touch locationInView:self.view].y) ;
if(CGRectContainsPoint([imgView frame], [touch locationInView:scrollview]))
{
[self ShowDetailView:imgView];
break;
}
}
}
任何機構幫我請 – user3222991
任何機構幫助我please.i我打這個issue..still我還沒有找到一個解決方案......... – user3222991