2010-11-23 4 views
1

내 리소스 폴더에 10 개의 로컬 HTML 파일이 있으며 ScrollViewImageView과 같은 페이징 효과를 적용하고 싶습니다. 어떻게 도와 드릴 수 있는지 알려주세요. webView에 HTML 페이지를 표시했지만 더 이상 아이디어가 없습니다. 내 코드는 (그러나 그것은 단지 하나의 페이지이다) : 엑스 코드 4.3.1에서UIWebView에서 페이징을 수행하려면 어떻게해야합니까?

arrHtmlPage=[[NSMutableArray alloc] initWithObjects:@"2",@"3",@"5",@"6",@"8",@"9",@"11",@"13",nil]; 

NSBundle *bundle = [NSBundle mainBundle]; 

NSString *htmlTemplateLink = [bundle pathForResource:@"2" ofType:@"htm"]; 

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlTemplateLink]]; 

wview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 768, 940)]; 
wview.scalesPageToFit = YES; 
[wview loadRequest:request]; 
wview.delegate=self; 

//wview.multipleTouchEnabled=YES; 
wview.userInteractionEnabled=YES; 

[self.view addSubview:wview]; 

답변

1
const CGFloat kScrollObjHeight = 900; 

const CGFloat kScrollObjWidth = 766; 

const NSUInteger kNumImages = 11; 



- (void)layoutScrollImages 

{ 

    UIImageView *view = nil; 
    NSArray *subviews = [scrollView1 subviews]; 


    // reposition all image subviews in a horizontal serial fashion 
    CGFloat curXLoc = 0; 
    for (view in subviews) 
    { 
     if ([view isKindOfClass:[UIWebView class]] && view.tag > 0) 
     { 
      CGRect frame = view.frame; 
      frame.origin = CGPointMake(curXLoc, 0); 
      view.frame = frame; 

      curXLoc += (kScrollObjWidth); 
     } 
    } 

    // set the content size so it can be scrollable 
    [scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)]; 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    arrHtmlPage=[[NSMutableArray alloc] initWithObjects:@"",@"2",@"3",@"4",@"5",@"6",@"8",@"9",@"11",@"12",@"13",@"14",nil]; 

    [scrollView1 setBackgroundColor:[UIColor blackColor]]; 
    [scrollView1 setCanCancelContentTouches:NO]; 
    scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite; 
    scrollView1.clipsToBounds = YES;  // default is NO, we want to restrict drawing within our scrollview 
    scrollView1.scrollEnabled = YES; 

    // pagingEnabled property default is NO, if set the scroller will stop or snap at each photo 
    // if you want free-flowing scroll, don't set this property. 
    scrollView1.pagingEnabled = YES; 



    int i; 
    for (i = 0; i <[arrHtmlPage count]; i++) 
    { 

     NSBundle *bundle = [NSBundle mainBundle]; 

     NSString *htmlTemplateLink = [bundle pathForResource:[arrHtmlPage objectAtIndex:i] ofType:@"htm"]; 

     NSLog(@"htmlTemplateLink==>%@",htmlTemplateLink); 

     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlTemplateLink]]; 
     wview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 766, 940) ]; 
     wview.backgroundColor=[UIColor redColor]; 
     wview.tag=i; 
     wview.scalesPageToFit = YES; 
     [wview loadRequest:request]; 

     wview.userInteractionEnabled=YES; 

     [scrollView1 addSubview:wview]; 


    } 

    [self layoutScrollImages]; 

} 



-(IBAction)buttonPressed:(id)sender 
{ 

    int pageNo = [sender tag] ; // current page no 
    int tempNo = pageNo%10 + 1; // total count 

    CGPoint bottomOffset = CGPointMake((tempNo-1) * 768,0); 
    [scrollView1 setContentOffset:bottomOffset animated:YES]; 
} 
0

새 프로젝트를 만들 수 있습니다. 파일 -> 새 프로젝트 -> 페이지 기반 응용 프로그램. 스토리 보드에 UIWebView를 드래그 앤 드롭합니다.

관련 문제