你好我一直在使用蘋果的滾動例如實現照片幻燈片與滾動型和ImageView的如何在iPhone中實現照片幻燈片放映?
- (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 in 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)];
}
這個作品fine.but圖像序列從這裏第一映像從圖像陣列,而不是我想要的任何圖片說像3號開始當頁面加載時我想先出現在視圖中,當我向左滾動時,它應該顯示圖像2號,當我向右滾動時,它應該顯示圖像4.我可以怎麼做? UPDATE: 我一直在使用下面的代碼來解決這個問題:
CGPoint lastFrame = CGPointMake((2* kScrollObjWidth), 0.0f);
[scrollView1 setContentOffset:lastFrame];
我已經使用以下代碼CGPoint lastFrame = CGPointMake((2 * kScrollObjWidth),0.0F)解決了這個問題; \t [scrollView1 setContentOffset:lastFrame]; – nehal 2011-04-22 12:58:37
非常好。將其張貼爲您自己的答案並在24小時內接受。 – 2011-04-22 13:00:20
@NickWeaver PageControl示例正是我正在尋找的。有一個迅速的版本?在obj-c中很難跟蹤。 – oyalhi 2015-12-29 17:44:07