iOS-UI- SetViewController-抽屉效果
SetViewController *setVC = [[SetViewController alloc]init];
// 注意坐标设置
setVC.view.frame = CGRectMake(-150, 0, 150, self.view.frame.size.height);
[self addChildViewController:setVC];
[self.view addSubview:setVC.view];
[setVC release];
// 增加边缘手势
UIScreenEdgePanGestureRecognizer *screenGR = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenAction:)];
screenGR.edges = UIRectEdgeLeft;
[self.view addGestureRecognizer:screenGR];
[screenGR release];
// 增加轻拍手势 点击收回抽屉
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
[self.firstVC.view addGestureRecognizer:tapGR];
[tapGR release];
抽屉效果实现
// 抽屉收回
(void)tapAction:(UITapGestureRecognizer *)sender
{NSLog(@"收回"); [UIView animateWithDuration:1.0 animations:^{ self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); }];
}
// 抽屉效果
(void)screenAction:(UIScreenEdgePanGestureRecognizer *)sender
{
// 防止一次操作 多次进入
if (UIGestureRecognizerStateEnded == sender.state) {NSLog(@"出来"); [UIView animateWithDuration:1.0 animations:^{ self.view.frame = CGRectMake(150, 0, self.view.frame.size.width, self.view.frame.size.height); }];
}
}