iphone中单点击/触摸UIWebView上的自定义控件覆盖

iphone中单点击/触摸UIWebView上的自定义控件覆盖,iphone,uiwebview,custom-controls,overlay,Iphone,Uiwebview,Custom Controls,Overlay,我想实现像著名的节应用程序截图显示的功能 内容在UIWebView的帮助下以html格式显示 在UIWebView上单击一次将显示两个覆盖控件(顶部和底部) 底部工具栏由控件和用于分页的滑块组成 请帮忙 我将如何通过以下方式实现上述目标: 如何构建这些自定义控件 单击一次,我将如何覆盖这些控件 如何组合UIToolbar(包含控件)和滑块 还有一个过渡幻灯片效果的需要,顶部标题来自屏幕顶部,底部控制和滑块来自屏幕底部。我将如何实现这一点 请为(a)-(d)详细地帮助我。一些代码指导将非常有用 谢

我想实现像著名的节应用程序截图显示的功能

  • 内容在UIWebView的帮助下以html格式显示

  • 在UIWebView上单击一次将显示两个覆盖控件(顶部和底部)

  • 底部工具栏由控件和用于分页的滑块组成

  • 请帮忙

    我将如何通过以下方式实现上述目标:

  • 如何构建这些自定义控件

  • 单击一次,我将如何覆盖这些控件

  • 如何组合UIToolbar(包含控件)和滑块

  • 还有一个过渡幻灯片效果的需要,顶部标题来自屏幕顶部,底部控制和滑块来自屏幕底部。我将如何实现这一点

  • 请为(a)-(d)详细地帮助我。一些代码指导将非常有用


    谢谢

    我正在做我最近一直在做的一个项目中你想要的事情

    基本上,我在UINavigationController中有一个UIWebView,其中有一个UIToolbar作为UIWebView的同级。我使用IB创建一个链接到我的视图控制器类的nib来设置所有这些的布局。我假定您知道如何使用IB以及如何正确设置所有代理、IBOutlet等,因此这里不介绍这些内容

    您需要在视图控制器中实现适当的委托,以便将其应用于所有工作。以下是我的视图控制器类接口:

    @interface MyViewController : UIViewController <UIWebViewDelegate, UIGestureRecognizerDelegate> {
    
    }
    
    @property (retain) IBOutlet UIWebView *webView;
    @property (retain) IBOutlet UINavigationItem *navigationItem;
    @property (retain) IBOutlet UIToolbar *toolbar;
    
    - (void)handleTapFrom:(UITapGestureRecognizer *)recognizer;
    
    // UIGestureRecognizerDelegate methods
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;
    
    // UIWebViewDelegate methods
    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
    - (void)webViewDidStartLoad:(UIWebView *)webView;
    - (void)webViewDidFinishLoad:(UIWebView *)webView;
    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
    
    @end
    
    我在控制器的viewDidLoad方法中的webView上注册UITapGestureRecognitor:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
    
        // I perform other appropriate initialization here like adding or removing items from the navigation bar or toolbar
    
        UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
        tapRecognizer.numberOfTapsRequired = 1;
        tapRecognizer.delegate = self;
        [self.webView addGestureRecognizer:tapRecognizer];
        [tapRecognizer release];
    }
    
    这是我的handleTapFrom回调:

    - (void)handleTapFrom:(UITapGestureRecognizer *)recognizer
    {
        CGPoint location = [recognizer locationInView:self.navigationController.topViewController.view];
        CGRect bounds = self.navigationController.topViewController.view.bounds;
    
        if (location.x < bounds.size.width / 5.0) {
            // This is in the left most quadrant
    
            // I implement code here to perform a "previous page" action
        } else if (location.x > bounds.size.width * 4.0 / 5.0) {
            // This is in the right most quadrant
    
            // I implement code here to perform a "next page" action
        } else if ((location.x > bounds.size.width / 3.0) && (location.x < bounds.size.width * 2.0 / 3.0)) {
            // This is in the middle third
            BOOL hidden = [self.navigationController isNavigationBarHidden];
    
            // resize the height of self.webView1, self.webView2, and self.webView3 based on the toolbar hiding / showing
            CGRect webViewControllerFrame = self.webView.frame;
            webViewControllerFrame.size.height += (hidden ? -44 : 44);
            self.webView.frame = webViewControllerFrame;
    
            // I hide all of the upper status bar and navigation bar, and bottom toolbar for a clean reading screen
            [[UIApplication sharedApplication] setStatusBarHidden:!hidden];
            [self.navigationController setNavigationBarHidden:!hidden animated:YES];
            self.toolbar.hidden = !hidden;
    
            // I perform content relayout here in the now modified webView screen real estate
        }
    }
    
    -(void)handleTapFrom:(UITapGestureRecognizer*)识别器
    {
    CGPoint location=[识别器位置视图:self.navigationController.topViewController.view];
    CGRect bounds=self.navigationController.topViewController.view.bounds;
    如果(位置xbounds.size.width*4.0/5.0){
    //这是最右边的象限
    //我在这里实现代码以执行“下一页”操作
    }else if((location.x>bounds.size.width/3.0)和&(location.x
    这个基本框架让我开始了,希望能回答你的问题,或者至少能为你指明正确的方向

    注:

    我还没有处理这样一个事实,即我可能会将点击理解为“显示/隐藏状态/导航/工具栏”,UIWebView可能会将此点击视为单击的链接,等等。我计划在短期内对此进行研究


    在节屏幕截图中显示的透明度不是什么大问题。您必须使用各种导航/工具栏上的alpha设置来完成此操作,并在上面的UIWebView上更改大小调整代码。事实上,我会定期覆盖一个额外的半透明工具栏,用于临时状态、警报等,并且不会调整UIWebView的大小,使其位于下方,并且通过此警报工具栏仍然可以看到。

    我正在做您在我最近工作的项目中寻找的事情

    基本上,我在UINavigationController中有一个UIWebView,其中有一个UIToolbar作为UIWebView的同级。我使用IB创建一个链接到我的视图控制器类的nib来设置所有这些的布局。我假定您知道如何使用IB以及如何正确设置所有代理、IBOutlet等,因此这里不介绍这些内容

    您需要在视图控制器中实现适当的委托,以便将其应用于所有工作。以下是我的视图控制器类接口:

    @interface MyViewController : UIViewController <UIWebViewDelegate, UIGestureRecognizerDelegate> {
    
    }
    
    @property (retain) IBOutlet UIWebView *webView;
    @property (retain) IBOutlet UINavigationItem *navigationItem;
    @property (retain) IBOutlet UIToolbar *toolbar;
    
    - (void)handleTapFrom:(UITapGestureRecognizer *)recognizer;
    
    // UIGestureRecognizerDelegate methods
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;
    
    // UIWebViewDelegate methods
    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
    - (void)webViewDidStartLoad:(UIWebView *)webView;
    - (void)webViewDidFinishLoad:(UIWebView *)webView;
    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
    
    @end
    
    我在控制器的viewDidLoad方法中的webView上注册UITapGestureRecognitor:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
    
        // I perform other appropriate initialization here like adding or removing items from the navigation bar or toolbar
    
        UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
        tapRecognizer.numberOfTapsRequired = 1;
        tapRecognizer.delegate = self;
        [self.webView addGestureRecognizer:tapRecognizer];
        [tapRecognizer release];
    }
    
    这是我的handleTapFrom回调:

    - (void)handleTapFrom:(UITapGestureRecognizer *)recognizer
    {
        CGPoint location = [recognizer locationInView:self.navigationController.topViewController.view];
        CGRect bounds = self.navigationController.topViewController.view.bounds;
    
        if (location.x < bounds.size.width / 5.0) {
            // This is in the left most quadrant
    
            // I implement code here to perform a "previous page" action
        } else if (location.x > bounds.size.width * 4.0 / 5.0) {
            // This is in the right most quadrant
    
            // I implement code here to perform a "next page" action
        } else if ((location.x > bounds.size.width / 3.0) && (location.x < bounds.size.width * 2.0 / 3.0)) {
            // This is in the middle third
            BOOL hidden = [self.navigationController isNavigationBarHidden];
    
            // resize the height of self.webView1, self.webView2, and self.webView3 based on the toolbar hiding / showing
            CGRect webViewControllerFrame = self.webView.frame;
            webViewControllerFrame.size.height += (hidden ? -44 : 44);
            self.webView.frame = webViewControllerFrame;
    
            // I hide all of the upper status bar and navigation bar, and bottom toolbar for a clean reading screen
            [[UIApplication sharedApplication] setStatusBarHidden:!hidden];
            [self.navigationController setNavigationBarHidden:!hidden animated:YES];
            self.toolbar.hidden = !hidden;
    
            // I perform content relayout here in the now modified webView screen real estate
        }
    }
    
    -(void)handleTapFrom:(UITapGestureRecognizer*)识别器
    {
    CGPoint location=[识别器位置视图:self.navigationController.topViewController.view];
    CGRect bounds=self.navigationController.topViewController.view.bounds;
    如果(位置xbounds.size.width*4.0/5.0){
    //这是最右边的象限
    //我在这里实现代码以执行“下一页”操作
    }else if((location.x>bounds.size.width/3.0)和&(location.x