Reputation: 443
i am newbie in iOS Development i make an application that Contain Two Scrollview one is in Big Size and Second is in Small Size that Shown in my Image and both are Contain Same images But First are Big in Size and Second Are Small in Size. here i want to make like as when i select any image From my Second Scrollview means small Scrollview then that image are Directly Shown in Big ScrollView like as a ViewPager or SegmentedControll in iOS how it is possible if it possible then please Give me Solution here my Image of Scrollview is.
Here i want when i select From Bottom Scrollview then i want Show that image in Upper Scrollview and here Both Scrollview is Contain Array of image and both are Same .
And Here code to set the imageview in scrollview
for(int index=0; index < [self.imagesa count]; index++)
{
NSDictionary *dict=[self.imagesa objectAtIndex:index];
NSString *image=[dict valueForKey:@"link"];
bigImage=[[UIImageView alloc]init];
bigImage.userInteractionEnabled=TRUE;
bigImage.bounds=CGRectMake(0, 0, self.zoomScroll.frame.size.width, self.zoomScroll.frame.size.height);
bigImage.frame=CGRectMake(index * self.zoomScroll.frame.size.width, 0, self.zoomScroll.frame.size.width, self.zoomScroll.frame.size.height);
[bigImage setMultipleTouchEnabled:YES];
[bigImage setTag:1];
[bigImage sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:[UIImage imageNamed:@"1.png"]];
[bigImage setUserInteractionEnabled:TRUE];
[self.objectarray insertObject:bigImage atIndex:index];
CGSize scrollViewSize=CGSizeMake(self.zoomScroll.frame.size.width*[self.objectarray count], self.zoomScroll.frame.size.height);
[self.zoomScroll setContentSize:scrollViewSize];
[self.zoomScroll addSubview:bigImage];
self.zoomScroll.clipsToBounds=YES;
[self.zoomScroll addSubview:[self.objectarray objectAtIndex:index]];
}
Here bigimage is imageview and zoomScroll is Scrollview and Code for Second means Small Scrollview is same only size of imageview and scrollview is Different.
And here Selection of Small image Code like as
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [[event allTouches] anyObject];
for(int index=0;index<[self.imageArray count];index++)
{
UIImageView *imgView = [self.imageArray 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:self.scrollView]))
{
[self ShowDetailView:imgView];
break;
}
}
}
and ShowDetailView method Code is
-(void)ShowDetailView:(UIImageView *)imgView
{
bigImage.image = imgView.image;
[self.zoomScroll addSubview:bigImage];
}
And also this method is in my Differnt Class File and here i import that Class.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.nextResponder touchesBegan:touches withEvent:event];
}
Upvotes: 0
Views: 397
Reputation: 1201
Ok in your small scrollview image. seta a tag for all image.
smallimage.tag = index;
and in this method
-(void)ShowDetailView:(UIImageView *)imgView
{
[self.zoomScroll setContentOffset:CGPointMake(imgView.tag * self.zoomScroll.frame.size.width, 0) animated:YES];
}
Upvotes: 1
Reputation: 213
There is a third party library called iCarousel , set two carousel views , that will work even like a table view where you can shift index and get the touch event easily.
https://github.com/nicklockwood/iCarousel
Upvotes: 1