如何在UIWebView中执行分页? [英] How can I perform Paging in UIWebView?

查看:96
本文介绍了如何在UIWebView中执行分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Resource文件夹中有十个本地HTML文件,我想执行ScrollViewImageView之类的分页效果,所以请帮助我如何做到这一点.我已经在webView中显示了HTML页面,但是我没有其他想法了.我的代码是(但仅用于一页):

I have ten local HTML files in my Resource folder and I want to performing paging effect like ScrollView and ImageView so please help me how I can do that. I have displayed HTML page in webView, but i don't have any more ideas. My code is (but it's for only One page):

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];  

推荐答案

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];
}

这篇关于如何在UIWebView中执行分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆