简体   繁体   中英

How to select One Scrollview Image into another Scrollview?

i am newbie in iOS Development.in my app Contain Two Scrollview one Scrollview is Big and One is Small Scrollview Here my Scrollview Contain Same Images but one contain Small And One Contain Big like as my Code

For Big 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.tag=123;
    bigImage.tag=index;
    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 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:[self.objectarray objectAtIndex:index]];
    self.zoomScroll.scrollEnabled=YES;
    self.zoomScroll.clipsToBounds=YES;

}

Here self.zoomScroll is my BigScrollview and is Width=300 width=270 and For Small Scrollview

for(int index=0; index < [self.imagesa count]; index++)
{
    NSDictionary *dict=[self.imagesa objectAtIndex:index];
    NSString *image=[dict valueForKey:@"link"];
    UIImageView *img = [[UIImageView alloc] init];
    img.tag=index;
    img.bounds = CGRectMake(10, 10, self.scrollView.frame.size.width, self.scrollView.frame.size.width);
    img.frame = CGRectMake(5+xOffset, 0, 50, 50);
    NSLog(@"image: %@",[self.imagesa objectAtIndex:index]);
    [img sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:[UIImage imageNamed:@"1.png"]];
    [self.imageArray insertObject:img atIndex:index];
    self.scrollView.contentSize = CGSizeMake(scrollWidth+xOffset,110);
    CALayer *borderLayer = [CALayer layer];
    CGRect borderFrame = CGRectMake(10, 10, (img.frame.size.width), (img.frame.size.height));
    [borderLayer setBackgroundColor:[[UIColor clearColor] CGColor]];
    [borderLayer setFrame:borderFrame];
    [borderLayer setCornerRadius:kCornerRadius];
    [borderLayer setBorderWidth:kBoarderWidth];
    [borderLayer setBorderColor:[[UIColor redColor] CGColor]];
    [img.layer addSublayer:borderLayer];
    [self.scrollView addSubview:img];
    [self.scrollView addSubview:[self.imageArray objectAtIndex:index]];
    NSLog(@"New Array %@",self.imageArray);
    xOffset += 60;
}

and self.scrollView is Small Scrollview and is Width=300 and Height=113

Here i want when i Scroll My Big Scrollview then My Small Scrollview Also Scrolled With Which image I selected in My Big Scrollview.How it is Possible like as in Android Give View Pager With Paging View. if it Possible then Give me Solution please.

Yes, paging also available in UIScrollView iOS too.

 @property(nonatomic, getter=isPagingEnabled) BOOL pagingEnabled 

^^^ above property you can set while creating instance of scrollview yeah in nib file if you created interface. Go through this doc for aditional information https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollview_class/index.html#//apple_ref/occ/instp/UIScrollView/pagingEnabled .

Now "you want to scroll smaller image view simultaneously bigger scrollview"
Yes it also possible you need to implement some delegates methods of scroll view like,

 - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView

and

 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

implement your scrolling logic of other scrollview here with the help of contentoffset of scrollview from delegate method.

 @property(nonatomic) CGPoint contentOffset 

using content offset property you can retrieve current location of content view which is scrolled. Apply same offset to other scrollview.

Also set tag values to imagesview inside scrollview. Using those tags you can set selected images on other scrollview too.

You can achieve same functionality Using icarousel for IOS here is the Tutorial that how can you use icarousel. http://www.theappguruz.com/tutorial/how-to-use-icarousel-view-controller-in-ios/ , Good Luck !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM