我想隐藏/取消隐藏灰色视图(有按钮),它位于奶油色/biege 色 webView 的顶部 -请参阅附图
我使用了 xcode 中提供的基于页面的应用程序模板。
方法 1:在控制器内隐藏/取消隐藏
我试图在同一个控制器中隐藏/取消隐藏,
但问题是每次创建此控制器的新实例并且隐藏/取消隐藏的布尔值丢失
方法 2:协议和委托
我也尝试使用委托/协议来维护其父控制器的状态,但它永远不会进入 if 块 -
if ([self.delegateReadingToolbar........ 块永远不会被调用。
-(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];
}
}
}
}
对于方法 2 编码:
子控制器.h
@class ChildController;
@protocol ReadingToolbarShowDelegate <NSObject>
-(void)contentViewDidFinish:(contentView *)controller showStatus:(BOOL)show;
@end
@property (nonatomic,weak)id<ReadingToolbarShowDelegate>delegateReadingToolbar;
父控制器.h
#import "ChildController.h"
@interface ParentController : UIViewController<UIPageViewControllerDataSource,UIPageViewControllerDelegate,ReadingToolbarShowDelegate>
父控制器.m
-(void)ChildControllerDidFinish:(contentView *)controller showStatus:(BOOL)show
{
showReadingToolbar = show;
}