简体   繁体   中英

how to hide/unhide view when taped on webview in page based application

I want to hide/unhide grey colored view(Which has button) and it is on top of cream/biege colored webView - please see attached pic

基于页面的应用

I have used an page based application template available in xcode.

Approach 1:Hide/unhide inside controller
i have tried to hide/unhide in same controller
but the problem is every time new instance of this controller created and bool values for hide/unhide are lost

Approach 2:Protocol & Delegates
I have also tried to use delegate/protocol to maintain its status from its parent controller but it never gets inside if block -
if ([self.delegateReadingToolbar........ block is never called.

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];

if(touch)
{

    CGPoint location = [touch locationInView: [touch view]];

    if (CGRectContainsPoint(webViewTouch,  location))
    {

        //do whatever
        NSLog(@"webView Touched");

        if (self.showReadingToolBar)
        {

            self.showReadingToolBar = NO; // approach 1
            self.viewReadingToolBar.hidden = NO;

            // approach 2
            if ([self.delegateReadingToolbar respondsToSelector:@selector(contentViewDidFinish:showStatus:)]) 
            { // this block is never called

                [self.delegateReadingToolbar contentViewDidFinish:self showStatus:NO];

            }


        }
        else
        {

            self.showReadingToolBar = YES;
            self.viewReadingToolBar.hidden = YES;
            [self.delegateReadingToolbar contentViewDidFinish:self showStatus:YES];

        }



    }
}

}

For Approach 2 Coding:

ChildController.h

@class ChildController;

@protocol ReadingToolbarShowDelegate <NSObject>

-(void)contentViewDidFinish:(contentView *)controller showStatus:(BOOL)show;

@end

@property (nonatomic,weak)id<ReadingToolbarShowDelegate>delegateReadingToolbar;

ParentController.h

#import "ChildController.h"

@interface ParentController :      UIViewController<UIPageViewControllerDataSource,UIPageViewControllerDelegate,ReadingToolbarShowDelegate>

ParentController.m

-(void)ChildControllerDidFinish:(contentView *)controller showStatus:(BOOL)show
{

   showReadingToolbar = show;
}

If you alloc/init a new controller the previously set values will be gone. You are essentially creating a new object. I see a couple of different ways you may be able to do this.

  1. Place your controllers inside a navigation controller and simply push the others on or off the stack. This way you don't have to instantiate a new object.

  2. You could save the desired display configuration In an NSUserDefaults key/value pair. Whenever you need to create a new object of this type it looks up the value in NSUserDefault.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM