我的目标:有一个滑动菜单,当它打开时会推送我的应用程序的当前视图。
我已经将我UINavigationController
的子类化,以便创建自定义“后退”按钮和从右侧菜单滑动。为此,在我的子类中,UINavigationController
我将当前UIViewController
( self.view.fram
) 的 x 原点更改为将其向左移动的值,x = -100;
这样做我将暴露右侧菜单。
完成上述操作后,我发现通过移动self.view
我也在移动可触摸区域,因此右侧菜单上的按钮将无法访问\可点击。
我已经阅读了很多内容pointInside
,hitTest
这可以帮助我实现我想要的,但仍然无法以适合我需要的方式实现它。
我知道 github 上有 1000 个开源项目,它们完全符合我的要求,但我想自己编写并更好地理解它。
谢谢。
NavControllerSubCls.h:
@interface NavControllerSubCls : UINavigationController <UINavigationControllerDelegate>
@property (nonatomic, strong) UIView *testView;
@property (nonatomic, strong) UIButton *rightMenuBtn;
@end
NavControllerSubCls.m:
-(void)viewDidLoad
{
[super viewDidLoad];
UIView *navBar = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 41)];
navBar.backgroundColor = [UIColor blueColor];
UIImageView *bkrNavBar = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 39)];
[navBar addSubview:bkrNavBar];
_rightMenuBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[_rightMenuBtn setFrame:CGRectMake(240, 20, 52, 19)];
[_rightMenuBtn setTitle:@"Click" forState:UIControlStateNormal];
[_rightMenuBtn addTarget:self action:@selector(showRightMenu) forControlEvents:UIControlEventTouchUpInside];
[navBar addSubview:_rightMenuBtn];
_testView = [[UIView alloc]initWithFrame:CGRectMake(300, 20, 120, 100)];
_testView.backgroundColor = [UIColor greenColor];
UIButton *testBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
testBtn.frame = CGRectMake(0, 0, 120, 100);
[testBtn addTarget:self action:@selector(doSomething) forControlEvents:UIControlEventTouchUpInside];
[_testView addSubview:testBtn];
[self.view addSubview:_testView];
[self.view addSubview:navBar];
[self.view insertSubview:_testView aboveSubview:self.view];
}
-(void)doSomething
{
NSLog(@"I'm Working!");
}
- (void)showRightMenu
{
CGRect frame = self.view.frame;
frame.origin.x = -100;
self.view.frame = frame;
}