Hello i have implemented photo slideshow with scrollview and imageview using apple's scrolling example
- (void)viewDidLoad {
kNumImages=[parray count];
self.view.backgroundColor=[UIColor viewFlipsideBackgroundColor];
[scrollView1 setBackgroundColor:[UIColor blackColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle=UIScrollViewIndicatorStyleWhite;
scrollView1.clipsToBounds=YES;
scrollView1.scrollEnabled=YES;
scrollView1.pagingEnabled=YES;
scrollView1.minimumZoomScale=0.5;
scrollView1.delegate=self;
scrollView1.maximumZoomScale=6.0;
NSUInteger i;
for(i=0;i<kNumImages;i++)
{
NSURL *url=[NSURL URLWithString:[parray objectAtIndex:i]];
NSLog(@"url object at index %i is %@",i,url);
//NSString *imageName=[NSString stringWithFormat:@"image%d.jpg",i ];
UIImage *image=[UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
imageView=[[UIImageView alloc] initWithImage:image];
CGRect rect=imageView.frame;
rect.size.height=kScrollObjHeight;
rect.size.width=kScrollObjWidth;
imageView.frame=rect;
imageView.tag=i+1;
[scrollView1 addSubview:imageView];
[imageView release];
}
[self layoutScrollImages];
[super viewDidLoad];
}
-(void)layoutScrollImages
{
kNumImages=[parray count];
view=nil;
NSArray *subviews=[scrollView1 subviews];
CGFloat curXLoc=0;
for(view i开发者_如何转开发n subviews)
{
if([view isKindOfClass:[UIImageView class]] && view.tag>0)
{
CGRect frame=view.frame;
frame.origin=CGPointMake(curXLoc, 0);
view.frame=frame;
curXLoc+=(kScrollObjWidth);
}}
[scrollView1 setContentSize:CGSizeMake((kNumImages *kScrollObjWidth),[scrollView1 bounds].size.height)];
}
this works fine.but the image sequence here starts from first image from image array instead of that i want any image say image number 3 wants to appears first in view when page is loaded and when i scroll left it should show image no.2 and when i scroll right it should show image 4.How can i do that? UPDATE: i have solved the issue using following code:
CGPoint lastFrame = CGPointMake(( 2* kScrollObjWidth), 0.0f);
[scrollView1 setContentOffset:lastFrame];
I have solved the issue using following code:
CGPoint lastFrame = CGPointMake(( 2* kScrollObjWidth), 0.0f); [scrollView1 setContentOffset:lastFrame];
You should have a look at the PageControl which shows how paging works with a UIScrollView and connect it to UIPageControl. You could easily adapt that code and put in your array of images in the order you need. It's memory efficient: only three UIImageViews are used at the same time.
精彩评论