2011-05-03 4 views
1
내가 사용 photoslide 쇼를 구현 안녕하세요

애플의 스크롤 example.Below 코드입니다 :iphone에서 uiscrollview 내부에있는 uiimageview에서 꼬집음을 집어 넣는 방법을 구현하는 방법은 무엇입니까?

- (void)viewDidLoad { 

    appDelegate=[(FoodAppDelegate *)[UIApplicationsharedApplication]delegate]; 
    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; 
    scrollView1.bouncesZoom=YES; 
    NSLog(@"view did load called"); 
    NSUInteger i; 
    for(i=0;i<kNumImages;i++) 
    { 
     NSLog(@"for loop of view did load called"); 
     NSURL *url=[NSURL URLWithString:[parray objectAtIndex:i]]; 
     NSLog(@"url object at index %i is %@",i,url); 
     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]; 

    } 
    [scrollView1 setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)]; 
    [self layoutScrollImages]; 
    [super viewDidLoad]; 
} 



-(void)layoutScrollImages 
{ 
    int c=appDelegate.selectedphoto-1; 
    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),200)]; 
    CGPoint lastFrame = CGPointMake((c* kScrollObjWidth), 0.0f); 
    [scrollView1 setContentOffset:lastFrame]; 
    scrollView1.showsHorizontalScrollIndicator=NO; 
    scrollView1.showsVerticalScrollIndicator=NO; 

} 

지금은 내가 그렇게 할 수 out.How 줌에서 줌을 구현하려는 샘플 코드 또는 예?

답변

0

그 안에 uiimageview가있는 uiscrollview 내에서 uiscrollview를 만듭니다. 외부 uiscrollview는 가로로 스크롤하고 내부는 핀치 및 확대/축소를 위해 설정됩니다. IOS는 실제로 내부 스크롤러가 완전히 축소되거나 가장자리에있을 때 상위 uiscrollview에 참여할 정도로 똑똑합니다.

핀치/확대/축소 앱 uiscrollview를 만드는 데 많은 예제가 있습니다.

-(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll { 
return contentView;} 
:

scrollView=[[UIScrollView alloc] initWithFrame:[BFCoords sharedBFCoords].APP_RECT]; 
scrollView.scrollEnabled=YES; 
scrollView.maximumZoomScale=1; 
scrollView.minimumZoomScale=.5; 
scrollView.delegate=self; 
scrollView.clipsToBounds=YES; 



contentView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, [BFCoords sharedBFCoords].APP_WIDTH*2, [BFCoords sharedBFCoords].APP_HEIGHT*2)]; 
scrollView.contentSize=CGSizeMake([BFCoords sharedBFCoords].APP_WIDTH*2, [BFCoords sharedBFCoords].APP_HEIGHT*2); 

[scrollView addSubview:contentView]; 

[self addSubview:scrollView]; 

scrollView.zoomScale=.5; 
[scrollView setBackgroundColor:[UIColor blueColor]]; 
self.hidden=NO; 
self.alpha=1; 

[contentView release]; 
[scrollView release]; 

가있는 ScrollView의 줌이가 UIScrollViewDelegate

를 구현하고 추가하는 것을 잊지 마세요 만들려면